2019-01-01 01:42:09 +08:00
|
|
|
cmake_minimum_required(VERSION 3.1)
|
2015-04-27 04:47:40 +08:00
|
|
|
|
2017-07-29 17:59:09 +08:00
|
|
|
##
|
|
|
|
## PROJECT
|
|
|
|
## name and version
|
|
|
|
##
|
2020-08-06 19:45:29 +08:00
|
|
|
project(nlohmann_json VERSION 3.9.1 LANGUAGES CXX)
|
2015-04-27 04:47:40 +08:00
|
|
|
|
2017-08-15 02:45:33 +08:00
|
|
|
##
|
|
|
|
## INCLUDE
|
|
|
|
##
|
|
|
|
##
|
|
|
|
include(ExternalProject)
|
|
|
|
|
2017-07-29 17:59:09 +08:00
|
|
|
##
|
|
|
|
## OPTIONS
|
|
|
|
##
|
2020-06-27 02:47:36 +08:00
|
|
|
|
|
|
|
if (POLICY CMP0077)
|
|
|
|
# Allow CMake 3.13+ to override options when using FetchContent / add_subdirectory.
|
|
|
|
cmake_policy(SET CMP0077 NEW)
|
|
|
|
endif ()
|
|
|
|
|
2017-12-21 00:54:45 +08:00
|
|
|
option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ON)
|
2018-11-02 17:15:27 +08:00
|
|
|
option(JSON_Install "Install CMake targets during install step." ON)
|
2018-01-13 20:07:03 +08:00
|
|
|
option(JSON_MultipleHeaders "Use non-amalgamated version of the library." OFF)
|
2020-07-23 19:11:48 +08:00
|
|
|
option(JSON_ImplicitConversions "Enable implicit conversions." ON)
|
2016-05-08 23:30:24 +08:00
|
|
|
|
2017-07-29 17:59:09 +08:00
|
|
|
##
|
|
|
|
## CONFIGURATION
|
|
|
|
##
|
2019-07-16 23:44:32 +08:00
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
2017-07-29 17:59:09 +08:00
|
|
|
set(NLOHMANN_JSON_TARGET_NAME ${PROJECT_NAME})
|
2019-07-16 23:44:32 +08:00
|
|
|
set(NLOHMANN_JSON_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE INTERNAL "")
|
|
|
|
set(NLOHMANN_JSON_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
|
2017-07-29 17:59:09 +08:00
|
|
|
set(NLOHMANN_JSON_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
|
|
|
|
set(NLOHMANN_JSON_CMAKE_CONFIG_TEMPLATE "cmake/config.cmake.in")
|
2018-04-09 23:32:18 +08:00
|
|
|
set(NLOHMANN_JSON_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}")
|
2017-07-29 17:59:09 +08:00
|
|
|
set(NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
|
|
|
|
set(NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Config.cmake")
|
2018-04-09 23:32:18 +08:00
|
|
|
set(NLOHMANN_JSON_CMAKE_PROJECT_TARGETS_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Targets.cmake")
|
2020-07-27 22:54:16 +08:00
|
|
|
set(NLOHMANN_JSON_PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
2015-04-27 04:47:40 +08:00
|
|
|
|
2018-01-13 20:07:03 +08:00
|
|
|
if (JSON_MultipleHeaders)
|
2018-01-29 18:21:11 +08:00
|
|
|
set(NLOHMANN_JSON_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/include/")
|
2018-02-10 21:46:39 +08:00
|
|
|
message(STATUS "Using the multi-header code from ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}")
|
2018-01-13 20:07:03 +08:00
|
|
|
else()
|
2018-01-29 18:21:11 +08:00
|
|
|
set(NLOHMANN_JSON_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/single_include/")
|
2018-02-10 21:46:39 +08:00
|
|
|
message(STATUS "Using the single-header code from ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}")
|
2018-01-13 20:07:03 +08:00
|
|
|
endif()
|
|
|
|
|
2020-07-23 19:11:48 +08:00
|
|
|
if (NOT JSON_ImplicitConversions)
|
|
|
|
message(STATUS "Implicit conversions are disabled")
|
|
|
|
endif()
|
|
|
|
|
2017-07-29 17:59:09 +08:00
|
|
|
##
|
|
|
|
## TARGET
|
|
|
|
## create target and add include path
|
|
|
|
##
|
|
|
|
add_library(${NLOHMANN_JSON_TARGET_NAME} INTERFACE)
|
2018-04-09 23:32:18 +08:00
|
|
|
add_library(${PROJECT_NAME}::${NLOHMANN_JSON_TARGET_NAME} ALIAS ${NLOHMANN_JSON_TARGET_NAME})
|
2019-03-28 21:22:48 +08:00
|
|
|
if (${CMAKE_VERSION} VERSION_LESS "3.8.0")
|
2019-01-16 21:21:49 +08:00
|
|
|
target_compile_features(${NLOHMANN_JSON_TARGET_NAME} INTERFACE cxx_range_for)
|
|
|
|
else()
|
|
|
|
target_compile_features(${NLOHMANN_JSON_TARGET_NAME} INTERFACE cxx_std_11)
|
|
|
|
endif()
|
2018-03-28 00:51:30 +08:00
|
|
|
|
2020-07-16 17:11:35 +08:00
|
|
|
target_compile_definitions(
|
|
|
|
${NLOHMANN_JSON_TARGET_NAME}
|
|
|
|
INTERFACE
|
|
|
|
JSON_USE_IMPLICIT_CONVERSIONS=$<BOOL:${JSON_ImplicitConversions}>
|
|
|
|
)
|
|
|
|
|
2017-07-29 17:59:09 +08:00
|
|
|
target_include_directories(
|
|
|
|
${NLOHMANN_JSON_TARGET_NAME}
|
2017-12-05 18:27:03 +08:00
|
|
|
INTERFACE
|
2018-01-29 18:21:11 +08:00
|
|
|
$<BUILD_INTERFACE:${NLOHMANN_JSON_INCLUDE_BUILD_DIR}>
|
2017-12-05 18:27:03 +08:00
|
|
|
$<INSTALL_INTERFACE:include>
|
2017-07-29 17:59:09 +08:00
|
|
|
)
|
2017-11-26 17:31:33 +08:00
|
|
|
|
2018-04-09 03:46:25 +08:00
|
|
|
## add debug view definition file for msvc (natvis)
|
2018-04-07 19:15:44 +08:00
|
|
|
if (MSVC)
|
2017-11-30 20:26:45 +08:00
|
|
|
set(NLOHMANN_ADD_NATVIS TRUE)
|
|
|
|
set(NLOHMANN_NATVIS_FILE "nlohmann_json.natvis")
|
2017-11-29 06:43:39 +08:00
|
|
|
target_sources(
|
2018-11-02 16:35:17 +08:00
|
|
|
${NLOHMANN_JSON_TARGET_NAME}
|
|
|
|
INTERFACE
|
2017-11-30 20:26:45 +08:00
|
|
|
$<INSTALL_INTERFACE:${NLOHMANN_NATVIS_FILE}>
|
2018-11-02 16:35:17 +08:00
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${NLOHMANN_NATVIS_FILE}>
|
2017-11-29 06:43:39 +08:00
|
|
|
)
|
|
|
|
endif()
|
2018-04-07 19:15:44 +08:00
|
|
|
|
2019-08-09 05:36:27 +08:00
|
|
|
# Install a pkg-config file, so other tools can find this.
|
|
|
|
CONFIGURE_FILE(
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/pkg-config.pc.in"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
|
|
|
|
)
|
|
|
|
|
2017-07-29 17:59:09 +08:00
|
|
|
##
|
|
|
|
## TESTS
|
|
|
|
## create and configure the unit test target
|
|
|
|
##
|
2017-12-21 00:54:45 +08:00
|
|
|
include(CTest) #adds option BUILD_TESTING (default ON)
|
|
|
|
|
|
|
|
if(BUILD_TESTING AND JSON_BuildTests)
|
2017-07-27 22:50:24 +08:00
|
|
|
enable_testing()
|
2016-05-11 08:25:54 +08:00
|
|
|
add_subdirectory(test)
|
2016-05-08 23:30:24 +08:00
|
|
|
endif()
|
2016-04-25 15:36:05 +08:00
|
|
|
|
2017-07-29 17:59:09 +08:00
|
|
|
##
|
|
|
|
## INSTALL
|
|
|
|
## install header files, generate and install cmake config files for find_package()
|
|
|
|
##
|
2016-04-25 16:23:14 +08:00
|
|
|
include(CMakePackageConfigHelpers)
|
2020-04-18 03:44:12 +08:00
|
|
|
# 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
|
2019-09-11 11:41:38 +08:00
|
|
|
configure_file(
|
|
|
|
"cmake/nlohmann_jsonConfigVersion.cmake.in"
|
|
|
|
${NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE}
|
|
|
|
@ONLY
|
2017-07-29 17:59:09 +08:00
|
|
|
)
|
2018-09-27 01:08:49 +08:00
|
|
|
configure_file(
|
2017-07-29 17:59:09 +08:00
|
|
|
${NLOHMANN_JSON_CMAKE_CONFIG_TEMPLATE}
|
|
|
|
${NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE}
|
2018-09-27 01:08:49 +08:00
|
|
|
@ONLY
|
2017-07-29 17:59:09 +08:00
|
|
|
)
|
2018-01-29 18:21:11 +08:00
|
|
|
|
2018-11-02 17:15:27 +08:00
|
|
|
if(JSON_Install)
|
2017-11-30 20:26:45 +08:00
|
|
|
install(
|
2018-11-02 17:15:27 +08:00
|
|
|
DIRECTORY ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}
|
|
|
|
DESTINATION ${NLOHMANN_JSON_INCLUDE_INSTALL_DIR}
|
|
|
|
)
|
|
|
|
install(
|
|
|
|
FILES ${NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE} ${NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE}
|
|
|
|
DESTINATION ${NLOHMANN_JSON_CONFIG_INSTALL_DIR}
|
|
|
|
)
|
|
|
|
if (NLOHMANN_ADD_NATVIS)
|
|
|
|
install(
|
|
|
|
FILES ${NLOHMANN_NATVIS_FILE}
|
|
|
|
DESTINATION .
|
|
|
|
)
|
2020-05-23 00:21:37 +08:00
|
|
|
endif()
|
2018-11-02 17:15:27 +08:00
|
|
|
export(
|
|
|
|
TARGETS ${NLOHMANN_JSON_TARGET_NAME}
|
|
|
|
NAMESPACE ${PROJECT_NAME}::
|
|
|
|
FILE ${NLOHMANN_JSON_CMAKE_PROJECT_TARGETS_FILE}
|
|
|
|
)
|
|
|
|
install(
|
|
|
|
TARGETS ${NLOHMANN_JSON_TARGET_NAME}
|
|
|
|
EXPORT ${NLOHMANN_JSON_TARGETS_EXPORT_NAME}
|
|
|
|
INCLUDES DESTINATION ${NLOHMANN_JSON_INCLUDE_INSTALL_DIR}
|
|
|
|
)
|
|
|
|
install(
|
|
|
|
EXPORT ${NLOHMANN_JSON_TARGETS_EXPORT_NAME}
|
|
|
|
NAMESPACE ${PROJECT_NAME}::
|
|
|
|
DESTINATION ${NLOHMANN_JSON_CONFIG_INSTALL_DIR}
|
|
|
|
)
|
2019-08-09 05:36:27 +08:00
|
|
|
install(
|
2020-07-28 06:15:18 +08:00
|
|
|
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
|
2020-07-27 22:54:16 +08:00
|
|
|
DESTINATION ${NLOHMANN_JSON_PKGCONFIG_INSTALL_DIR}
|
2019-08-09 05:36:27 +08:00
|
|
|
)
|
2017-11-30 20:26:45 +08:00
|
|
|
endif()
|