Skip to content

Commit bdef2bd

Browse files
author
Dan Huantes
committed
UnitTest++ now correctly supports CMake's find_package config mode
[CMakeLists.txt] - Bumped cmake minimum requirement to go to 3.0 as this appears to be earliest version that transitive usage requirements are supported. - Added version to project so that is evident when looking at CMakeLists.txt - Removed include_directories as that command affects more than just UnitTest++ in favor of target_include_directories. - The target_include_directories uses the generator expressions to do the same thing for the BUILD_INTERFACE condition but only affects UnitTest++. The INSTALL_INTERFACE ensures that when UnitTest++ is installed client applications calling find_package for UnitTest++ only have to add the UnitTest++ target to the target_link_libraries and will get the correct include path for UnitTest++ added to their include paths. - Added DEBUG_POSTFIX to both library and unit test to distinguish them from each other as they are installed into the same directory and would otherwise overwrite one another. - Added Versioning using write_basic_package_version_file to the install so that a client can call find_package(UnitTest++ 2.1 REQUIRED) and it will be able to confirm the version. If the version is updated you could theoretically ahve a version 2.2, 2.3 ,etc... and the find_package mechanism will find the correct one. the SameMajorVersion option in that call indicates that 2.3 is compatible with 2.1 or in other words if find_package(UnitTest++ 2.1 REQUIRED) is called and 2.3 is installed that satisfies the condition but if only 3.0 was installed it will fail because of 'SameMajorVersion'. - Also added installation for the Version file.
1 parent bc5d87f commit bdef2bd

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

CMakeLists.txt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
cmake_minimum_required(VERSION 2.8.1)
2-
project(UnitTest++)
1+
cmake_minimum_required(VERSION 3.0)
2+
project(UnitTest++ VERSION 2.1)
33

44
option(UTPP_USE_PLUS_SIGN
55
"Set this to OFF if you wish to use '-cpp' instead of '++' in lib/include paths"
@@ -74,7 +74,7 @@ endif()
7474
file(GLOB TEST_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} tests/*.cpp tests/*.h)
7575
source_group( "" FILES ${TEST_SRCS})
7676
add_executable(TestUnitTest++ ${TEST_SRCS})
77-
include_directories(.)
77+
7878

7979
if(${UTPP_USE_PLUS_SIGN})
8080
set_target_properties(TestUnitTest++ PROPERTIES OUTPUT_NAME TestUnitTest++)
@@ -100,13 +100,30 @@ else()
100100
set (UTPP_INSTALL_DESTINATION "include/UnitTestPP")
101101
endif()
102102

103+
target_include_directories( UnitTest++
104+
PUBLIC
105+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
106+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include/UnitTest++>
107+
)
108+
set_target_properties(UnitTest++ PROPERTIES DEBUG_POSTFIX "-d")
109+
set_target_properties(TestUnitTest++ PROPERTIES DEBUG_POSTFIX "-d")
110+
103111
set(config_install_dir_ lib${LIB_SUFFIX}/cmake/${PROJECT_NAME})
104112
set(targets_export_name_ "${PROJECT_NAME}Targets")
113+
include(CMakePackageConfigHelpers)
114+
write_basic_package_version_file(
115+
cmake/UnitTest++ConfigVersion.cmake
116+
VERSION ${UnitTest++_VERSION}
117+
COMPATIBILITY SameMajorVersion
118+
)
105119

106120
install(TARGETS UnitTest++ EXPORT "${targets_export_name_}" DESTINATION lib${LIB_SUFFIX})
107121
install(FILES ${headers_} DESTINATION ${UTPP_INSTALL_DESTINATION})
108122
install(FILES ${platformHeaders_} DESTINATION ${UTPP_INSTALL_DESTINATION}/${platformDir_})
109-
install(FILES cmake/UnitTest++Config.cmake DESTINATION "${config_install_dir_}")
123+
install(FILES
124+
cmake/UnitTest++Config.cmake
125+
${CMAKE_CURRENT_BINARY_DIR}/cmake/UnitTest++ConfigVersion.cmake
126+
DESTINATION "${config_install_dir_}")
110127
install(EXPORT "${targets_export_name_}" DESTINATION "${config_install_dir_}")
111128

112129
set(prefix ${CMAKE_INSTALL_PREFIX})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy