Skip to content

Commit

Permalink
- exported targets go to separate generated file and package config …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
sergeyrachev authored and cdunn2001 committed May 5, 2021
1 parent 94cda30 commit b640795
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
10 changes: 10 additions & 0 deletions jsoncppConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit b640795

Please sign in to comment.