From f4be0ada85327e230fa274571eb7f2fb102fb434 Mon Sep 17 00:00:00 2001 From: JackBoosY Date: Mon, 7 Jun 2021 02:12:20 -0700 Subject: [PATCH] Use modern cmake function export to generate target --- CMakeLists.txt | 9 +++++++++ RapidJSONConfig.cmake.in | 16 +++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dc2072a..45437ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -194,6 +194,11 @@ install(FILES readme.md DESTINATION "${DOC_INSTALL_DIR}" COMPONENT doc) +# Add an interface target to export it +add_library(RapidJSON INTERFACE) + +target_include_directories(RapidJSON INTERFACE $) + install(DIRECTORY include/rapidjson DESTINATION "${INCLUDE_INSTALL_DIR}" COMPONENT dev) @@ -220,6 +225,7 @@ SET( CONFIG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) SET( CONFIG_DIR ${CMAKE_CURRENT_BINARY_DIR}) SET( ${PROJECT_NAME}_INCLUDE_DIR "\${${PROJECT_NAME}_SOURCE_DIR}/include" ) +INCLUDE(CMakePackageConfigHelpers) CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake @ONLY ) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}ConfigVersion.cmake.in @@ -246,3 +252,6 @@ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake DESTINATION "${CMAKE_INSTALL_DIR}" COMPONENT dev) + +INSTALL(TARGETS RapidJSON EXPORT RapidJSON-targets) +INSTALL(EXPORT RapidJSON-targets DESTINATION ${CMAKECONFIG_INSTALL_DIR}) \ No newline at end of file diff --git a/RapidJSONConfig.cmake.in b/RapidJSONConfig.cmake.in index c25d312..a8ca78f 100644 --- a/RapidJSONConfig.cmake.in +++ b/RapidJSONConfig.cmake.in @@ -1,6 +1,6 @@ -################################################################################ -# CMake minimum version required -cmake_minimum_required(VERSION 3.0) +@PACKAGE_INIT@ + +include ("${CMAKE_CURRENT_LIST_DIR}/RapidJSON-targets.cmake") ################################################################################ # RapidJSON source dir @@ -14,12 +14,6 @@ set( RapidJSON_DIR "@CONFIG_DIR@") # Compute paths get_filename_component(RapidJSON_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) -set( RapidJSON_INCLUDE_DIR "@RapidJSON_INCLUDE_DIR@" ) -set( RapidJSON_INCLUDE_DIRS "@RapidJSON_INCLUDE_DIR@" ) -message(STATUS "RapidJSON found. Headers: ${RapidJSON_INCLUDE_DIRS}") +get_target_property(RapidJSON_INCLUDE_DIR RapidJSON INTERFACE_INCLUDE_DIRECTORIES) -if(NOT TARGET rapidjson) - add_library(rapidjson INTERFACE IMPORTED) - set_property(TARGET rapidjson PROPERTY - INTERFACE_INCLUDE_DIRECTORIES ${RapidJSON_INCLUDE_DIRS}) -endif() +set( RapidJSON_INCLUDE_DIRS ${RapidJSON_INCLUDE_DIR} )