From f871471d9020788eb0c05582f6430cca36397424 Mon Sep 17 00:00:00 2001 From: Dan Huantes Date: Tue, 7 Apr 2020 18:07:24 -0500 Subject: [PATCH] Added Namespace to Exported Target [CMakeLists.txt] - It is standard practice to have a namespace for an imported target. Added UnitTest++:: as the namespace argument so that find_package(UnitTest++) will result in UnitTest++::UnitTest++ target that will be used in target_link_libraries. - Updated target_link_libraries for TestUnitTest++ as an example --- CMakeLists.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a3fb55..b4c75c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,8 @@ source_group(${platformDir_} FILES ${platformHeaders_} ${platformSources_}) # create the lib add_library(UnitTest++ STATIC ${headers_} ${sources_} ${platformHeaders_} ${platformSources_}) +add_library(UnitTest++::UnitTest++ ALIAS UnitTest++) + if(${UTPP_USE_PLUS_SIGN}) set_target_properties(UnitTest++ PROPERTIES OUTPUT_NAME UnitTest++) @@ -80,7 +82,10 @@ if(${UTPP_USE_PLUS_SIGN}) set_target_properties(TestUnitTest++ PROPERTIES OUTPUT_NAME TestUnitTest++) endif() -target_link_libraries(TestUnitTest++ UnitTest++) +target_link_libraries(TestUnitTest++ + PUBLIC + UnitTest++::UnitTest++ + ) # run unit tests as post build step add_custom_command(TARGET TestUnitTest++ @@ -124,7 +129,7 @@ install(FILES cmake/UnitTest++Config.cmake ${CMAKE_CURRENT_BINARY_DIR}/cmake/UnitTest++ConfigVersion.cmake DESTINATION "${config_install_dir_}") -install(EXPORT "${targets_export_name_}" DESTINATION "${config_install_dir_}") +install(EXPORT "${targets_export_name_}" NAMESPACE "UnitTest++::" DESTINATION "${config_install_dir_}") set(prefix ${CMAKE_INSTALL_PREFIX}) set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin)