mirror of
https://github.com/unittest-cpp/unittest-cpp
synced 2026-09-26 16:19:30 +03:00
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.
This commit is contained in:
parent
bc5d87f484
commit
bdef2bdd62
1 changed files with 21 additions and 4 deletions
|
|
@ -1,5 +1,5 @@
|
|||
cmake_minimum_required(VERSION 2.8.1)
|
||||
project(UnitTest++)
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
project(UnitTest++ VERSION 2.1)
|
||||
|
||||
option(UTPP_USE_PLUS_SIGN
|
||||
"Set this to OFF if you wish to use '-cpp' instead of '++' in lib/include paths"
|
||||
|
|
@ -74,7 +74,7 @@ endif()
|
|||
file(GLOB TEST_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} tests/*.cpp tests/*.h)
|
||||
source_group( "" FILES ${TEST_SRCS})
|
||||
add_executable(TestUnitTest++ ${TEST_SRCS})
|
||||
include_directories(.)
|
||||
|
||||
|
||||
if(${UTPP_USE_PLUS_SIGN})
|
||||
set_target_properties(TestUnitTest++ PROPERTIES OUTPUT_NAME TestUnitTest++)
|
||||
|
|
@ -100,13 +100,30 @@ else()
|
|||
set (UTPP_INSTALL_DESTINATION "include/UnitTestPP")
|
||||
endif()
|
||||
|
||||
target_include_directories( UnitTest++
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include/UnitTest++>
|
||||
)
|
||||
set_target_properties(UnitTest++ PROPERTIES DEBUG_POSTFIX "-d")
|
||||
set_target_properties(TestUnitTest++ PROPERTIES DEBUG_POSTFIX "-d")
|
||||
|
||||
set(config_install_dir_ lib${LIB_SUFFIX}/cmake/${PROJECT_NAME})
|
||||
set(targets_export_name_ "${PROJECT_NAME}Targets")
|
||||
include(CMakePackageConfigHelpers)
|
||||
write_basic_package_version_file(
|
||||
cmake/UnitTest++ConfigVersion.cmake
|
||||
VERSION ${UnitTest++_VERSION}
|
||||
COMPATIBILITY SameMajorVersion
|
||||
)
|
||||
|
||||
install(TARGETS UnitTest++ EXPORT "${targets_export_name_}" DESTINATION lib${LIB_SUFFIX})
|
||||
install(FILES ${headers_} DESTINATION ${UTPP_INSTALL_DESTINATION})
|
||||
install(FILES ${platformHeaders_} DESTINATION ${UTPP_INSTALL_DESTINATION}/${platformDir_})
|
||||
install(FILES cmake/UnitTest++Config.cmake DESTINATION "${config_install_dir_}")
|
||||
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_}")
|
||||
|
||||
set(prefix ${CMAKE_INSTALL_PREFIX})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue