Skip to content

Commit b220de4

Browse files
committed
- 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.
1 parent b1bd848 commit b220de4

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,13 @@ if(JSONCPP_WITH_CMAKE_PACKAGE)
177177
include(CMakePackageConfigHelpers)
178178
install(EXPORT jsoncpp
179179
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp
180-
FILE jsoncppConfig.cmake)
180+
FILE jsoncpp-targets.cmake)
181+
configure_package_config_file(jsoncppConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfig.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp)
182+
181183
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfigVersion.cmake"
182184
VERSION ${PROJECT_VERSION}
183185
COMPATIBILITY SameMajorVersion)
184-
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfigVersion.cmake
186+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfigVersion.cmake ${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfig.cmake
185187
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp)
186188
endif()
187189

jsoncppConfig.cmake.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cmake_policy(PUSH)
2+
cmake_policy(VERSION 3.0)
3+
4+
@PACKAGE_INIT@
5+
6+
include ( "${CMAKE_CURRENT_LIST_DIR}/jsoncpp-targets.cmake" )
7+
8+
check_required_components(JsonCpp)
9+
10+
cmake_policy(POP)

0 commit comments

Comments
 (0)