Skip to content

Commit f871471

Browse files
author
Dan Huantes
committed
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
1 parent c269666 commit f871471

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ source_group(${platformDir_} FILES ${platformHeaders_} ${platformSources_})
6464

6565
# create the lib
6666
add_library(UnitTest++ STATIC ${headers_} ${sources_} ${platformHeaders_} ${platformSources_})
67+
add_library(UnitTest++::UnitTest++ ALIAS UnitTest++)
68+
6769

6870
if(${UTPP_USE_PLUS_SIGN})
6971
set_target_properties(UnitTest++ PROPERTIES OUTPUT_NAME UnitTest++)
@@ -80,7 +82,10 @@ if(${UTPP_USE_PLUS_SIGN})
8082
set_target_properties(TestUnitTest++ PROPERTIES OUTPUT_NAME TestUnitTest++)
8183
endif()
8284

83-
target_link_libraries(TestUnitTest++ UnitTest++)
85+
target_link_libraries(TestUnitTest++
86+
PUBLIC
87+
UnitTest++::UnitTest++
88+
)
8489

8590
# run unit tests as post build step
8691
add_custom_command(TARGET TestUnitTest++
@@ -124,7 +129,7 @@ install(FILES
124129
cmake/UnitTest++Config.cmake
125130
${CMAKE_CURRENT_BINARY_DIR}/cmake/UnitTest++ConfigVersion.cmake
126131
DESTINATION "${config_install_dir_}")
127-
install(EXPORT "${targets_export_name_}" DESTINATION "${config_install_dir_}")
132+
install(EXPORT "${targets_export_name_}" NAMESPACE "UnitTest++::" DESTINATION "${config_install_dir_}")
128133

129134
set(prefix ${CMAKE_INSTALL_PREFIX})
130135
set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin)

0 commit comments

Comments
 (0)