From e88121f69e1b4bf36e9d72b129f27ee7b1ed6fdb Mon Sep 17 00:00:00 2001 From: Jason Horsburgh Date: Tue, 15 Mar 2016 12:14:19 +0000 Subject: [PATCH] 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 ...) 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. --- CMakeLists.txt | 9 +++++++-- cmake/UnitTest++Config.cmake | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 cmake/UnitTest++Config.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c573ef9..ea7cf24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,6 +69,11 @@ else() set (UTPP_INSTALL_DESTINATION "include/UnitTestPP") endif() -install(TARGETS UnitTest++ DESTINATION lib) +set(config_install_dir_ lib/cmake/${PROJECT_NAME}) +set(targets_export_name_ "${PROJECT_NAME}Targets") + +install(TARGETS UnitTest++ EXPORT "${targets_export_name_}" DESTINATION lib) install(FILES ${headers_} DESTINATION ${UTPP_INSTALL_DESTINATION}) -install(FILES ${platformHeaders_} DESTINATION ${UTPP_INSTALL_DESTINATION}/${platformDir_}) \ No newline at end of file +install(FILES ${platformHeaders_} DESTINATION ${UTPP_INSTALL_DESTINATION}/${platformDir_}) +install(FILES cmake/UnitTest++Config.cmake DESTINATION "${config_install_dir_}") +install(EXPORT "${targets_export_name_}" DESTINATION "${config_install_dir_}") diff --git a/cmake/UnitTest++Config.cmake b/cmake/UnitTest++Config.cmake new file mode 100644 index 0000000..afe165c --- /dev/null +++ b/cmake/UnitTest++Config.cmake @@ -0,0 +1,2 @@ +include("${CMAKE_CURRENT_LIST_DIR}/UnitTest++Targets.cmake") +get_filename_component(UTPP_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/../../../include/" ABSOLUTE)