- 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.
This commit is contained in:
Sergey Rachev 2021-02-27 18:25:11 +01:00 committed by Christopher Dunn
parent 94cda30dbd
commit b640795571
2 changed files with 14 additions and 2 deletions

View File

@ -177,11 +177,13 @@ if(JSONCPP_WITH_CMAKE_PACKAGE)
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
install(EXPORT jsoncpp install(EXPORT jsoncpp
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/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" write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfigVersion.cmake"
VERSION ${PROJECT_VERSION} VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion) 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) DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp)
endif() endif()

10
jsoncppConfig.cmake.in Normal file
View File

@ -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)