From 4550aaeb090ef959a7a17732927d61d58fcfe7d5 Mon Sep 17 00:00:00 2001 From: Matthias Gabriel Date: Wed, 31 Jan 2018 15:26:19 +0100 Subject: [PATCH] add cmake package config --- CMakeLists.txt | 32 ++++++++++++++++++++++++++++++++ config.cmake.in | 6 ++++++ 2 files changed, 38 insertions(+) create mode 100644 config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 65f1927b..4e264fab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -403,3 +403,35 @@ if(NOT WIN32 OR NOT CMAKE_HOST_SYSTEM_NAME MATCHES Windows) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/catch.pc DESTINATION ${PKGCONFIG_INSTALL_DIR}) endif() + + +#### create a cmake package config +## install a cmake package config +set(PACKAGE_NAME "catch") +set(PACKAGE_NAMESPACE "catchorg::") + +# package config files and folders +set(CONFIG_INSTALL_DIR "lib/cmake/${PACKAGE_NAME}") +set(CONFIG_GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated") +set(VERSION_CONFIG_FILE "${CONFIG_GENERATED_DIR}/${PACKAGE_NAME}ConfigVersion.cmake") +set(PACKAGE_CONFIG_FILE "${CONFIG_GENERATED_DIR}/${PACKAGE_NAME}Config.cmake") +set(TARGETS_EXPORT_NAME "${PACKAGE_NAME}Targets") + +# target for export +add_library(catch INTERFACE) +target_include_directories(catch INTERFACE "$" "$") + +# write package config files +include(CMakePackageConfigHelpers) +write_basic_package_version_file("${VERSION_CONFIG_FILE}" COMPATIBILITY SameMajorVersion) +configure_package_config_file( + "${CMAKE_SOURCE_DIR}/config.cmake.in" + "${PACKAGE_CONFIG_FILE}" + INSTALL_DESTINATION "${CONFIG_INSTALL_DIR}" +) + +# install the files +install(FILES "${PACKAGE_CONFIG_FILE}" "${VERSION_CONFIG_FILE}" DESTINATION "${CONFIG_INSTALL_DIR}") +install(EXPORT "${TARGETS_EXPORT_NAME}" NAMESPACE "${PACKAGE_NAMESPACE}" DESTINATION "${CONFIG_INSTALL_DIR}") +install(TARGETS ${PACKAGE_NAME} EXPORT "${TARGETS_EXPORT_NAME}") + diff --git a/config.cmake.in b/config.cmake.in new file mode 100644 index 00000000..51d46d0c --- /dev/null +++ b/config.cmake.in @@ -0,0 +1,6 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") +check_required_components("@PACKAGE_NAME@") + +