cJSON: Use CMakePackageConfigHelpers
CMake discourages the use of configure_file() to generate files such as cJSONConfig.cmake because it might expand variables such as <project>_INCLUDE_DIR to absolute paths, which might cause issues on Windows and macOS [1]. Instead, configure_package_config_file() is meant as a drop-in replacement that generates cJSONConfig.cmake using relative paths. In the context of this project, this should allow pre-compiled versions of the `3rdParty` directory to be shared among developers. [1]: https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@9610 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: dc7f18be6bfa6f933909544176af600c48755173 Former-commit-id: 93228e7d1f46efa51dd919c3ce20e4b735c58726
This commit is contained in:
parent
846ae9924e
commit
b47e5f5bf3
3 changed files with 30 additions and 6 deletions
|
@ -682,6 +682,18 @@ if(OPTION_CJSON)
|
|||
URL ${CJSON_URL}
|
||||
URL_HASH ${CJSON_HASH}
|
||||
CMAKE_ARGS ${CJSON_ARGS})
|
||||
ExternalProject_Add_Step(${CJSON_PROJECT} cjson_add_cmake
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"${CMAKE_SOURCE_DIR}/patches/cJSON/CMakeLists.txt"
|
||||
"<SOURCE_DIR>/CMakeLists.txt"
|
||||
DEPENDEES update # do after update
|
||||
DEPENDERS patch) # do before patch
|
||||
ExternalProject_Add_Step(${CJSON_PROJECT} cjson_add_cmakeconfig
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"${CMAKE_SOURCE_DIR}/patches/cJSON/cJSONConfig.cmake.in"
|
||||
"<SOURCE_DIR>/cJSONConfig.cmake.in"
|
||||
DEPENDEES update # do after update
|
||||
DEPENDERS patch) # do before patch
|
||||
else()
|
||||
set(CJSON_PROJECT )
|
||||
endif()
|
||||
|
|
|
@ -223,12 +223,20 @@ if(ENABLE_CJSON_UTILS)
|
|||
endif()
|
||||
|
||||
# create the other package config files
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/library_config/cJSONConfig.cmake.in"
|
||||
${PROJECT_BINARY_DIR}/cJSONConfig.cmake @ONLY)
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/library_config/cJSONConfigVersion.cmake.in"
|
||||
${PROJECT_BINARY_DIR}/cJSONConfigVersion.cmake @ONLY)
|
||||
include(CMakePackageConfigHelpers)
|
||||
set(include_dir "${CMAKE_INSTALL_INCLUDEDIR}/cjson")
|
||||
configure_package_config_file(cJSONConfig.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/cJSONConfig.cmake
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cJSON
|
||||
PATH_VARS
|
||||
include_dir
|
||||
CMAKE_INSTALL_LIBDIR
|
||||
)
|
||||
write_basic_package_version_file(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/cJSONConfigVersion.cmake
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY SameMajorVersion
|
||||
)
|
||||
|
||||
if(ENABLE_TARGET_EXPORT)
|
||||
# Install package config files
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
@PACKAGE_INIT@
|
||||
set_and_check(cJSON_INCLUDE_DIRS "@PACKAGE_include_dir@")
|
||||
set_and_check(cJSON_LIBRARIES "@PACKAGE_CMAKE_INSTALL_LIBDIR@")
|
||||
check_required_components(cJSON)
|
Loading…
Reference in a new issue