From b6407955712b51837cc3dc07ee5e6143761027c6 Mon Sep 17 00:00:00 2001 From: Sergey Rachev Date: Sat, 27 Feb 2021 18:25:11 +0100 Subject: [PATCH] - exported targets go to separate generated file and package config file generated from template to use automatic package resolving and resolution logic CMake provides helpers to generate config file. Generated config file has usefull macro check_required_components() to set necessary variables like PackageName_FOUND if requirements has been satisfied. An absence of dedicated config file confuses user project as necessary variables are not set. --- CMakeLists.txt | 6 ++++-- jsoncppConfig.cmake.in | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 jsoncppConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ad82f9..23aaeee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -177,11 +177,13 @@ if(JSONCPP_WITH_CMAKE_PACKAGE) include(CMakePackageConfigHelpers) install(EXPORT jsoncpp DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp - FILE jsoncppConfig.cmake) + FILE jsoncpp-targets.cmake) + configure_package_config_file(jsoncppConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfig.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp) + write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfigVersion.cmake" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfigVersion.cmake + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfigVersion.cmake ${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfig.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp) endif() diff --git a/jsoncppConfig.cmake.in b/jsoncppConfig.cmake.in new file mode 100644 index 0000000..e3fa4b9 --- /dev/null +++ b/jsoncppConfig.cmake.in @@ -0,0 +1,10 @@ +cmake_policy(PUSH) +cmake_policy(VERSION 3.0) + +@PACKAGE_INIT@ + +include ( "${CMAKE_CURRENT_LIST_DIR}/jsoncpp-targets.cmake" ) + +check_required_components(JsonCpp) + +cmake_policy(POP) \ No newline at end of file