From 1729db85c159f855138095f20e8a15c4a520a8ef Mon Sep 17 00:00:00 2001 From: Chuck Atkins Date: Wed, 26 Sep 2018 13:08:49 -0400 Subject: [PATCH] cmake: fix package config to deal with versioning and namespaces --- CMakeLists.txt | 5 ++--- cmake/config.cmake.in | 14 ++++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 99376704..3d6ea093 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,10 +86,10 @@ include(CMakePackageConfigHelpers) write_basic_package_version_file( ${NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE} COMPATIBILITY SameMajorVersion ) -configure_package_config_file( +configure_file( ${NLOHMANN_JSON_CMAKE_CONFIG_TEMPLATE} ${NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE} - INSTALL_DESTINATION ${NLOHMANN_JSON_CONFIG_INSTALL_DIR} + @ONLY ) install( @@ -121,4 +121,3 @@ install( NAMESPACE ${PROJECT_NAME}:: DESTINATION ${NLOHMANN_JSON_CONFIG_INSTALL_DIR} ) -export(PACKAGE ${PROJECT_NAME}) \ No newline at end of file diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in index 8d52ae14..9a17a7d7 100644 --- a/cmake/config.cmake.in +++ b/cmake/config.cmake.in @@ -1,9 +1,15 @@ -@PACKAGE_INIT@ +include(FindPackageHandleStandardArgs) +set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG ${CMAKE_CURRENT_LIST_FILE}) +find_package_handle_standard_args(@PROJECT_NAME@ CONFIG_MODE) + if(NOT TARGET @PROJECT_NAME@::@NLOHMANN_JSON_TARGET_NAME@) include("${CMAKE_CURRENT_LIST_DIR}/@NLOHMANN_JSON_TARGETS_EXPORT_NAME@.cmake") if((NOT TARGET @NLOHMANN_JSON_TARGET_NAME@) AND - (PACKAGE_FIND_VERSION VERSION_LESS 3.2.0)) - add_library(@NLOHMANN_JSON_TARGET_NAME@ ALIAS @PROJECT_NAME@::@NLOHMANN_JSON_TARGET_NAME@) + (NOT @PROJECT_NAME@_FIND_VERSION OR + @PROJECT_NAME@_FIND_VERSION VERSION_LESS 3.2.0)) + add_library(@NLOHMANN_JSON_TARGET_NAME@ INTERFACE IMPORTED) + set_target_properties(@NLOHMANN_JSON_TARGET_NAME@ PROPERTIES + INTERFACE_LINK_LIBRARIES @PROJECT_NAME@::@NLOHMANN_JSON_TARGET_NAME@ + ) endif() endif() -check_required_components("@PROJECT_NAME@")