10000 Add support for CMake find_package() · Reification/unittest-cpp@e88121f · GitHub
[go: up one dir, main page]

Skip to content

Commit e88121f

Browse files
Add support for CMake find_package()
Added export configuration for UnitTest++ target and installed the export and config file in libs/cmake/UnitTest++. Added basic UnitTest++Config.cmake file which includes exported targets file and sets UTPP_INCLUDE_DIRS to the install location of the includes directory, this allows UnitTest++ to be used as a normal target in your own CMakeLists.txt file. e.g.: find_package(UnitTest++ REQUIRED NO_MODULE) add_executable(foo ...) 10000 include_directories(${UTPP_INCLUDE_DIRS}) target_link_libraries(foo UnitTest++) which will ensure the library and installed headers paths are set up correctly for your own target.
1 parent b69b63a commit e88121f

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ else()
6969
set (UTPP_INSTALL_DESTINATION "include/UnitTestPP")
7070
endif()
7171

72-
install(TARGETS UnitTest++ DESTINATION lib)
72+
set(config_install_dir_ lib/cmake/${PROJECT_NAME})
73+
set(targets_export_name_ "${PROJECT_NAME}Targets")
74+
75+
install(TARGETS UnitTest++ EXPORT "${targets_export_name_}" DESTINATION lib)
7376
install(FILES ${headers_} DESTINATION ${UTPP_INSTALL_DESTINATION})
74-
install(FILES ${platformHeaders_} DESTINATION ${UTPP_INSTALL_DESTINATION}/${platformDir_})
77+
install(FILES ${platformHeaders_} DESTINATION ${UTPP_INSTALL_DESTINATION}/${platformDir_})
78+
install(FILES cmake/UnitTest++Config.cmake DESTINATION "${config_install_dir_}")
79+
install(EXPORT "${targets_export_name_}" DESTINATION "${config_install_dir_}")

cmake/UnitTest++Config.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include("${CMAKE_CURRENT_LIST_DIR}/UnitTest++Targets.cmake")
2+
get_filename_component(UTPP_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/../../../include/" ABSOLUTE)

0 commit comments

Comments
 (0)
0