Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace CMake targets #822

Open
msimberg opened this issue Apr 28, 2023 · 0 comments
Open

Namespace CMake targets #822

msimberg opened this issue Apr 28, 2023 · 0 comments

Comments

@msimberg
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Bad diagnostics if one forgets to find Umpire before linking to the CMake target.

Describe the solution you'd like

CMake targets would be namespaced with Umpire::, e.g. Umpire::umpire.

Describe alternatives you've considered

Do nothing.

Additional context

It's generally considered good practice to namespace exported CMake targets to avoid conflicts with other packages. The name conflict concern is lower in this case. Namespacing makes it clear that this is a CMake target and not a plain library. If one is linking with target_link_libraries(target umpire) but one has forgotten to find Umpire first there will eventually be a linking error with a plain

/nix/store/f4qnwzv6y0nq8lix33jr5ykkyybs6fxf-binutils-2.40/bin/ld: cannot find -lumpire: No such file or directory

This does not tell me that I forgot to find Umpire.

On the other hand, if the target is Umpire::umpire and I forget to find Umpire I instead get during configuration:

CMake Warning (dev) at CMakeLists.txt:4 (target_link_libraries):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "test" links to:

    Umpire::umpire

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

This warning is for project developers.  Use -Wno-dev to suppress it.

which is far clearer. Depending on if the above is an error or not it may continue with

/nix/store/f4qnwzv6y0nq8lix33jr5ykkyybs6fxf-binutils-2.40/bin/ld: cannot find -lUmpire::umpire: No such file or directory

which is a clear sign that it's trying to use a CMake target as a plain library.

For additional context, this didn't come up for me in the main project configuration, but in a generated PackageConfig.cmake file which was missing find_dependency(Umpire), where it's much easier to forget to find a package.

I think it may be as simple as adding NAMESPACE UMPIRE to this call:

install(EXPORT umpire-targets DESTINATION lib/cmake/umpire)
. But you may of course have other concerns (backwards compatibility etc.).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant