[CMake] Supporting imported targets with and without namespaces

Wilke, Jeremiah J jjwilke at sandia.gov
Thu Dec 6 13:55:55 EST 2018


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.

Thanks,
Jeremy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20181206/cdaf2353/attachment.html>


More information about the CMake mailing list