Supporting imported targets with and without namespaces

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Supporting imported targets with and without namespaces

CMake mailing list

We are cleaning up the cmake in our project. Targets are not currently exported with namespaces, but ideally should be.  However, we have enough users based on the old cmake that we don’t want to require people to use the namespaced target (for a while).

I couldn’t find recommendations on this in documentation or list archives.


  1. Even when the exported target is namespace::imported_lib, this still seems to work:
    target_link_libraries(myLib imported_lib)
    which I did not understand.
  2. AFAIK, you cannot ALIAS an imported target in the config file:
    add_library(imported_lib ALIAS namespace::imported_lib)
    so that both the namespace and non-namespaced versions are valid
  3. It did work to use the following in the config file:
    add_library(imported_lib INTERFACE)
    target_link_libraries(imported_lib INTERFACE namespace::imported_lib)
    but this just feels like the wrong way to do it


Any help would be greatly appreciated.





Powered by

Please keep messages on-topic and check the CMake FAQ at:

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support:
CMake Consulting:
CMake Training Courses:

Visit other Kitware open-source projects at

Follow this link to subscribe/unsubscribe: