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
This commit is contained in:
Dan Huantes 2020-04-07 18:07:24 -05:00
parent c269666681
commit f871471d90

View file

@ -64,6 +64,8 @@ source_group(${platformDir_} FILES ${platformHeaders_} ${platformSources_})
# create the lib # create the lib
add_library(UnitTest++ STATIC ${headers_} ${sources_} ${platformHeaders_} ${platformSources_}) add_library(UnitTest++ STATIC ${headers_} ${sources_} ${platformHeaders_} ${platformSources_})
add_library(UnitTest++::UnitTest++ ALIAS UnitTest++)
if(${UTPP_USE_PLUS_SIGN}) if(${UTPP_USE_PLUS_SIGN})
set_target_properties(UnitTest++ PROPERTIES OUTPUT_NAME UnitTest++) 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++) set_target_properties(TestUnitTest++ PROPERTIES OUTPUT_NAME TestUnitTest++)
endif() endif()
target_link_libraries(TestUnitTest++ UnitTest++) target_link_libraries(TestUnitTest++
PUBLIC
UnitTest++::UnitTest++
)
# run unit tests as post build step # run unit tests as post build step
add_custom_command(TARGET TestUnitTest++ add_custom_command(TARGET TestUnitTest++
@ -124,7 +129,7 @@ install(FILES
cmake/UnitTest++Config.cmake cmake/UnitTest++Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/UnitTest++ConfigVersion.cmake ${CMAKE_CURRENT_BINARY_DIR}/cmake/UnitTest++ConfigVersion.cmake
DESTINATION "${config_install_dir_}") 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(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin) set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin)