Use CMakePackageConfigHelpers to generate module configuration
This commit is contained in:
parent
37453d0903
commit
3efc881192
@ -94,21 +94,33 @@ configure_file(
|
|||||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
|
||||||
)
|
)
|
||||||
|
|
||||||
# generate CMake module configuration and version files
|
include(CMakePackageConfigHelpers)
|
||||||
configure_file(
|
|
||||||
|
# generate CMake module configuration file
|
||||||
|
configure_package_config_file(
|
||||||
${JSON_CMAKE_CONFIG_TEMPLATE}
|
${JSON_CMAKE_CONFIG_TEMPLATE}
|
||||||
${JSON_CMAKE_PROJECT_CONFIG_FILE}
|
${JSON_CMAKE_PROJECT_CONFIG_FILE}
|
||||||
@ONLY
|
INSTALL_DESTINATION ${JSON_CONFIG_INSTALL_DIR}
|
||||||
|
NO_SET_AND_CHECK_MACRO
|
||||||
)
|
)
|
||||||
|
|
||||||
# use a custom package version config file instead of
|
# generate CMake module version file
|
||||||
# write_basic_package_version_file to ensure that it's architecture-independent
|
if(CMAKE_VERSION VERSION_EQUAL "3.14" OR CMAKE_VERSION VERSION_GREATER "3.14")
|
||||||
# https://github.com/nlohmann/json/issues/1697
|
write_basic_package_version_file(
|
||||||
configure_file(
|
${JSON_CMAKE_VERSION_CONFIG_FILE}
|
||||||
|
COMPATIBILITY SameMajorVersion
|
||||||
|
ARCH_INDEPENDENT
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
# use a custom package version config file instead of
|
||||||
|
# write_basic_package_version_file to ensure that it's architecture-independent
|
||||||
|
# https://github.com/nlohmann/json/issues/1697
|
||||||
|
configure_file(
|
||||||
"cmake/nlohmann_jsonConfigVersion.cmake.in"
|
"cmake/nlohmann_jsonConfigVersion.cmake.in"
|
||||||
${JSON_CMAKE_VERSION_CONFIG_FILE}
|
${JSON_CMAKE_VERSION_CONFIG_FILE}
|
||||||
@ONLY
|
@ONLY
|
||||||
)
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
# install files and targets
|
# install files and targets
|
||||||
|
|||||||
@ -1,15 +1,16 @@
|
|||||||
include(FindPackageHandleStandardArgs)
|
@PACKAGE_INIT@
|
||||||
set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG ${CMAKE_CURRENT_LIST_FILE})
|
|
||||||
find_package_handle_standard_args(@PROJECT_NAME@ CONFIG_MODE)
|
|
||||||
|
|
||||||
if(NOT TARGET @PROJECT_NAME@::@JSON_TARGET_NAME@)
|
include(FindPackageHandleStandardArgs)
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/@JSON_TARGETS_EXPORT_NAME@.cmake")
|
set(nlohmann_json_CONFIG ${CMAKE_CURRENT_LIST_FILE})
|
||||||
if((NOT TARGET @JSON_TARGET_NAME@) AND
|
find_package_handle_standard_args(nlohmann_json CONFIG_MODE)
|
||||||
(NOT @PROJECT_NAME@_FIND_VERSION OR
|
|
||||||
@PROJECT_NAME@_FIND_VERSION VERSION_LESS 3.2.0))
|
if(NOT TARGET nlohmann_json::nlohmann_json)
|
||||||
add_library(@JSON_TARGET_NAME@ INTERFACE IMPORTED)
|
include("${CMAKE_CURRENT_LIST_DIR}/nlohmann_jsonTargets.cmake")
|
||||||
set_target_properties(@JSON_TARGET_NAME@ PROPERTIES
|
if((NOT TARGET nlohmann_json)
|
||||||
INTERFACE_LINK_LIBRARIES @PROJECT_NAME@::@JSON_TARGET_NAME@
|
AND (NOT nlohmann_json_FIND_VERSION OR nlohmann_json_FIND_VERSION VERSION_LESS 3.2.0))
|
||||||
)
|
add_library(nlohmann_json INTERFACE IMPORTED)
|
||||||
|
set_target_properties(nlohmann_json PROPERTIES INTERFACE_LINK_LIBRARIES nlohmann_json::nlohmann_json)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
check_required_components(nlohmann_json)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user