2018-12-31 20:42:09 +03:00
|
|
|
cmake_minimum_required(VERSION 3.1)
|
2015-04-26 23:47:40 +03:00
|
|
|
|
2017-07-29 12:59:09 +03:00
|
|
|
##
|
|
|
|
## PROJECT
|
|
|
|
## name and version
|
|
|
|
##
|
2022-08-02 00:27:58 +03:00
|
|
|
project(nlohmann_json VERSION 3.11.1 LANGUAGES CXX)
|
2015-04-26 23:47:40 +03:00
|
|
|
|
2020-12-09 13:37:01 +03:00
|
|
|
##
|
|
|
|
## MAIN_PROJECT CHECK
|
2020-12-13 22:34:51 +03:00
|
|
|
## determine if nlohmann_json is built as a subproject (using add_subdirectory) or if it is the main project
|
2020-12-09 13:37:01 +03:00
|
|
|
##
|
2020-12-09 14:39:44 +03:00
|
|
|
set(MAIN_PROJECT OFF)
|
2020-12-13 22:34:51 +03:00
|
|
|
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
2021-05-12 16:55:06 +03:00
|
|
|
set(MAIN_PROJECT ON)
|
2020-12-09 13:37:01 +03:00
|
|
|
endif()
|
|
|
|
|
2017-08-14 21:45:33 +03:00
|
|
|
##
|
|
|
|
## INCLUDE
|
|
|
|
##
|
|
|
|
##
|
2022-03-24 09:54:07 +03:00
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
|
2017-08-14 21:45:33 +03:00
|
|
|
include(ExternalProject)
|
|
|
|
|
2017-07-29 12:59:09 +03:00
|
|
|
##
|
|
|
|
## OPTIONS
|
|
|
|
##
|
2020-06-26 21:47:36 +03:00
|
|
|
|
|
|
|
if (POLICY CMP0077)
|
|
|
|
# Allow CMake 3.13+ to override options when using FetchContent / add_subdirectory.
|
|
|
|
cmake_policy(SET CMP0077 NEW)
|
|
|
|
endif ()
|
|
|
|
|
2022-03-24 09:54:07 +03:00
|
|
|
# VERSION_GREATER_EQUAL is not available in CMake 3.1
|
|
|
|
if(${MAIN_PROJECT} AND (${CMAKE_VERSION} VERSION_EQUAL 3.13 OR ${CMAKE_VERSION} VERSION_GREATER 3.13))
|
|
|
|
set(JSON_BuildTests_INIT ON)
|
|
|
|
else()
|
|
|
|
set(JSON_BuildTests_INIT OFF)
|
|
|
|
endif()
|
2022-05-29 14:08:06 +03:00
|
|
|
option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ${JSON_BuildTests_INIT})
|
|
|
|
option(JSON_CI "Enable CI build targets." OFF)
|
|
|
|
option(JSON_Diagnostics "Use extended diagnostic messages." OFF)
|
2022-07-31 18:38:52 +03:00
|
|
|
option(JSON_GlobalUDLs "Place use-defined string literals in the global namespace." ON)
|
2022-05-29 14:08:06 +03:00
|
|
|
option(JSON_ImplicitConversions "Enable implicit conversions." ON)
|
2022-06-16 20:34:32 +03:00
|
|
|
option(JSON_DisableEnumSerialization "Disable default integer enum serialization." OFF)
|
2022-05-29 14:08:06 +03:00
|
|
|
option(JSON_LegacyDiscardedValueComparison "Enable legacy discarded value comparison." OFF)
|
|
|
|
option(JSON_Install "Install CMake targets during install step." ${MAIN_PROJECT})
|
2022-06-14 09:54:12 +03:00
|
|
|
option(JSON_MultipleHeaders "Use non-amalgamated version of the library." ON)
|
2022-05-29 14:08:06 +03:00
|
|
|
option(JSON_SystemInclude "Include as system headers (skip for clang-tidy)." OFF)
|
2021-03-24 09:15:18 +03:00
|
|
|
|
|
|
|
if (JSON_CI)
|
2022-03-24 09:54:07 +03:00
|
|
|
include(ci)
|
2021-03-24 09:15:18 +03:00
|
|
|
endif ()
|
2016-05-08 18:30:24 +03:00
|
|
|
|
2017-07-29 12:59:09 +03:00
|
|
|
##
|
|
|
|
## CONFIGURATION
|
|
|
|
##
|
2019-07-16 18:44:32 +03:00
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
2017-07-29 12:59:09 +03:00
|
|
|
set(NLOHMANN_JSON_TARGET_NAME ${PROJECT_NAME})
|
2022-07-29 08:43:22 +03:00
|
|
|
set(NLOHMANN_JSON_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}" CACHE INTERNAL "")
|
2019-07-16 18:44:32 +03:00
|
|
|
set(NLOHMANN_JSON_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
|
2017-07-29 12:59:09 +03:00
|
|
|
set(NLOHMANN_JSON_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
|
|
|
|
set(NLOHMANN_JSON_CMAKE_CONFIG_TEMPLATE "cmake/config.cmake.in")
|
2018-04-09 18:32:18 +03:00
|
|
|
set(NLOHMANN_JSON_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}")
|
2017-07-29 12:59:09 +03: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 18:32:18 +03:00
|
|
|
set(NLOHMANN_JSON_CMAKE_PROJECT_TARGETS_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Targets.cmake")
|
2022-07-29 08:43:22 +03:00
|
|
|
set(NLOHMANN_JSON_PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/pkgconfig")
|
2015-04-26 23:47:40 +03:00
|
|
|
|
2018-01-13 15:07:03 +03:00
|
|
|
if (JSON_MultipleHeaders)
|
2018-01-29 13:21:11 +03:00
|
|
|
set(NLOHMANN_JSON_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/include/")
|
2018-02-10 16:46:39 +03:00
|
|
|
message(STATUS "Using the multi-header code from ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}")
|
2018-01-13 15:07:03 +03:00
|
|
|
else()
|
2018-01-29 13:21:11 +03:00
|
|
|
set(NLOHMANN_JSON_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/single_include/")
|
2018-02-10 16:46:39 +03:00
|
|
|
message(STATUS "Using the single-header code from ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}")
|
2018-01-13 15:07:03 +03:00
|
|
|
endif()
|
|
|
|
|
2020-07-23 14:11:48 +03:00
|
|
|
if (NOT JSON_ImplicitConversions)
|
|
|
|
message(STATUS "Implicit conversions are disabled")
|
|
|
|
endif()
|
|
|
|
|
2022-06-16 20:34:32 +03:00
|
|
|
if (JSON_DisableEnumSerialization)
|
|
|
|
message(STATUS "Enum integer serialization is disabled")
|
|
|
|
endif()
|
|
|
|
|
2022-05-29 14:08:06 +03:00
|
|
|
if (JSON_LegacyDiscardedValueComparison)
|
|
|
|
message(STATUS "Legacy discarded value comparison enabled")
|
|
|
|
endif()
|
|
|
|
|
2021-01-02 23:36:11 +03:00
|
|
|
if (JSON_Diagnostics)
|
|
|
|
message(STATUS "Diagnostics enabled")
|
|
|
|
endif()
|
|
|
|
|
2021-05-05 23:19:24 +03:00
|
|
|
if (JSON_SystemInclude)
|
|
|
|
set(NLOHMANN_JSON_SYSTEM_INCLUDE "SYSTEM")
|
|
|
|
endif()
|
|
|
|
|
2017-07-29 12:59:09 +03:00
|
|
|
##
|
|
|
|
## TARGET
|
|
|
|
## create target and add include path
|
|
|
|
##
|
|
|
|
add_library(${NLOHMANN_JSON_TARGET_NAME} INTERFACE)
|
2018-04-09 18:32:18 +03:00
|
|
|
add_library(${PROJECT_NAME}::${NLOHMANN_JSON_TARGET_NAME} ALIAS ${NLOHMANN_JSON_TARGET_NAME})
|
2019-03-28 16:22:48 +03:00
|
|
|
if (${CMAKE_VERSION} VERSION_LESS "3.8.0")
|
2019-01-16 16:21:49 +03: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-27 19:51:30 +03:00
|
|
|
|
2020-07-16 12:11:35 +03:00
|
|
|
target_compile_definitions(
|
|
|
|
${NLOHMANN_JSON_TARGET_NAME}
|
|
|
|
INTERFACE
|
2022-07-31 18:38:52 +03:00
|
|
|
$<$<NOT:$<BOOL:${JSON_GlobalUDLs}>>:JSON_USE_GLOBAL_UDLS=0>
|
2022-05-29 14:08:06 +03:00
|
|
|
$<$<NOT:$<BOOL:${JSON_ImplicitConversions}>>:JSON_USE_IMPLICIT_CONVERSIONS=0>
|
2022-06-16 20:34:32 +03:00
|
|
|
$<$<BOOL:${JSON_DisableEnumSerialization}>:JSON_DISABLE_ENUM_SERIALIZATION=1>
|
2022-05-29 14:08:06 +03:00
|
|
|
$<$<BOOL:${JSON_Diagnostics}>:JSON_DIAGNOSTICS=1>
|
|
|
|
$<$<BOOL:${JSON_LegacyDiscardedValueComparison}>:JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1>
|
2020-07-16 12:11:35 +03:00
|
|
|
)
|
|
|
|
|
2017-07-29 12:59:09 +03:00
|
|
|
target_include_directories(
|
|
|
|
${NLOHMANN_JSON_TARGET_NAME}
|
2021-05-05 23:19:24 +03:00
|
|
|
${NLOHMANN_JSON_SYSTEM_INCLUDE} INTERFACE
|
2018-01-29 13:21:11 +03:00
|
|
|
$<BUILD_INTERFACE:${NLOHMANN_JSON_INCLUDE_BUILD_DIR}>
|
2017-12-05 13:27:03 +03:00
|
|
|
$<INSTALL_INTERFACE:include>
|
2017-07-29 12:59:09 +03:00
|
|
|
)
|
2017-11-26 12:31:33 +03:00
|
|
|
|
2018-04-08 22:46:25 +03:00
|
|
|
## add debug view definition file for msvc (natvis)
|
2018-04-07 14:15:44 +03:00
|
|
|
if (MSVC)
|
2017-11-30 15:26:45 +03:00
|
|
|
set(NLOHMANN_ADD_NATVIS TRUE)
|
|
|
|
set(NLOHMANN_NATVIS_FILE "nlohmann_json.natvis")
|
2017-11-29 01:43:39 +03:00
|
|
|
target_sources(
|
2018-11-02 11:35:17 +03:00
|
|
|
${NLOHMANN_JSON_TARGET_NAME}
|
|
|
|
INTERFACE
|
2017-11-30 15:26:45 +03:00
|
|
|
$<INSTALL_INTERFACE:${NLOHMANN_NATVIS_FILE}>
|
2018-11-02 11:35:17 +03:00
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${NLOHMANN_NATVIS_FILE}>
|
2017-11-29 01:43:39 +03:00
|
|
|
)
|
|
|
|
endif()
|
2018-04-07 14:15:44 +03:00
|
|
|
|
2019-08-09 00:36:27 +03:00
|
|
|
# Install a pkg-config file, so other tools can find this.
|
|
|
|
CONFIGURE_FILE(
|
2021-05-12 16:55:06 +03:00
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/pkg-config.pc.in"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
|
2019-08-09 00:36:27 +03:00
|
|
|
)
|
|
|
|
|
2017-07-29 12:59:09 +03:00
|
|
|
##
|
|
|
|
## TESTS
|
|
|
|
## create and configure the unit test target
|
|
|
|
##
|
2020-12-09 13:37:01 +03:00
|
|
|
if (JSON_BuildTests)
|
2020-12-14 12:59:38 +03:00
|
|
|
include(CTest)
|
2017-07-27 17:50:24 +03:00
|
|
|
enable_testing()
|
2022-05-01 10:41:50 +03:00
|
|
|
add_subdirectory(tests)
|
2016-05-08 18:30:24 +03:00
|
|
|
endif()
|
2016-04-25 10:36:05 +03:00
|
|
|
|
2017-07-29 12:59:09 +03:00
|
|
|
##
|
|
|
|
## INSTALL
|
|
|
|
## install header files, generate and install cmake config files for find_package()
|
|
|
|
##
|
2016-04-25 11:23:14 +03:00
|
|
|
include(CMakePackageConfigHelpers)
|
2020-04-17 22:44:12 +03: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 06:41:38 +03:00
|
|
|
configure_file(
|
|
|
|
"cmake/nlohmann_jsonConfigVersion.cmake.in"
|
|
|
|
${NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE}
|
|
|
|
@ONLY
|
2017-07-29 12:59:09 +03:00
|
|
|
)
|
2018-09-26 20:08:49 +03:00
|
|
|
configure_file(
|
2017-07-29 12:59:09 +03:00
|
|
|
${NLOHMANN_JSON_CMAKE_CONFIG_TEMPLATE}
|
|
|
|
${NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE}
|
2018-09-26 20:08:49 +03:00
|
|
|
@ONLY
|
2017-07-29 12:59:09 +03:00
|
|
|
)
|
2018-01-29 13:21:11 +03:00
|
|
|
|
2018-11-02 12:15:27 +03:00
|
|
|
if(JSON_Install)
|
2017-11-30 15:26:45 +03:00
|
|
|
install(
|
2018-11-02 12:15:27 +03: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 .
|
|
|
|
)
|
2021-05-15 21:09:15 +03:00
|
|
|
endif()
|
2018-11-02 12:15:27 +03: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 00:36:27 +03:00
|
|
|
install(
|
2020-07-28 01:15:18 +03:00
|
|
|
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
|
2020-07-27 17:54:16 +03:00
|
|
|
DESTINATION ${NLOHMANN_JSON_PKGCONFIG_INSTALL_DIR}
|
2019-08-09 00:36:27 +03:00
|
|
|
)
|
2021-05-15 21:09:15 +03:00
|
|
|
endif()
|