Skip to content

CMake: Possible name clashes when depending on godot-cpp through add_subdirectory or FetchContent #1657

Closed

Description

@enetheru

Godot version

Any

godot-cpp version

a42b363

System information

any

Issue description

CMake is the gift that keeps giving.
While running some testing by separating the godot-cpp-test target into its own repo and fetching the godot-cpp source using the cmake FetchContent mechanism, it was brought to my attention that CMake has no current project level namespace mechanism to prevent target name collisions with adjacent or downstream projects.

This means that any consumers of godot-cpp will have to avoid/manage the target names we have defined ie. template_debug, template_release, editor, and godot-cpp-test.

This stack overflow question summs up the issues and provides adequate reading and resources to understand in more depth.
https://stackoverflow.com/questions/72931527/how-can-i-avoid-clashes-with-targets-imported-with-fetchcontent-makeavailable

This of course isnt a nice way to play in an ecosystem. Godot also provides the target alias mechanism, which we already use for godot-cpp::

I think it would be prudent to change the naming of the internal CMake targets to avoid clashes, something like godot-cpp.<target_name> works nicely.

The test target should also be disabled by default.

Steps to reproduce

To re-produce the issue:
A cmake c++ project
That uses find_package, add_subdirectory, or FetchContent to consume godot-cpp
That names their build targets the same as ours
Or consumes another library with the same target names as ours.

Minimal reproduction project

This issue is encountered when building an extension using cmake, prior to the use of a godot project.

Activity

  1. added
    bug
    on Nov 28, 2024
  2. added this to the 4.x milestone on Nov 28, 2024
  3. enetheru commented on Jan 11, 2025

    @enetheru
    CollaboratorAuthor

    this can be closed as #1658 has been merged

  4. dsnopek commented on Jan 11, 2025

    @dsnopek
    Collaborator

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcmake

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions