2018-12-31 20:42:09 +03:00
|
|
|
cmake_minimum_required(VERSION 3.1)
|
2015-04-26 23:47:40 +03:00
|
|
|
|
2022-09-22 20:52:27 +03:00
|
|
|
#############################################################################
|
|
|
|
|
# set up
|
|
|
|
|
#############################################################################
|
2022-09-22 12:40:10 +03:00
|
|
|
|
2022-09-22 20:52:27 +03:00
|
|
|
# set policies
|
2022-09-22 12:40:10 +03:00
|
|
|
if (POLICY CMP0077)
|
|
|
|
|
# Allow CMake 3.13+ to override options when using FetchContent / add_subdirectory.
|
|
|
|
|
cmake_policy(SET CMP0077 NEW)
|
|
|
|
|
endif ()
|
|
|
|
|
|
2022-09-22 20:52:27 +03:00
|
|
|
# set the CMake module path
|
|
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
|
2015-04-26 23:47:40 +03:00
|
|
|
|
2022-09-22 20:52:27 +03:00
|
|
|
# determine if nlohmann_json is the main project or built as a subproject (using add_subdirectory)
|
2022-09-22 12:21:52 +03:00
|
|
|
set(JSON_MAIN_PROJECT OFF)
|
2020-12-13 22:34:51 +03:00
|
|
|
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
2022-09-22 12:21:52 +03:00
|
|
|
set(JSON_MAIN_PROJECT ON)
|
2020-12-09 13:37:01 +03:00
|
|
|
endif()
|
|
|
|
|
|
2022-09-22 20:52:27 +03:00
|
|
|
# set project name and version
|
|
|
|
|
project(nlohmann_json VERSION 3.11.2 LANGUAGES CXX)
|
2017-08-14 21:45:33 +03:00
|
|
|
|
2022-09-22 20:52:27 +03:00
|
|
|
# print CMake, system, and compiler information
|
2022-09-22 16:04:02 +03:00
|
|
|
include(json_info)
|
|
|
|
|
|
2022-09-22 20:52:27 +03:00
|
|
|
# handle options and configuration
|
|
|
|
|
include(json_opts)
|
2021-03-24 09:15:18 +03:00
|
|
|
|
2022-09-22 20:52:27 +03:00
|
|
|
#############################################################################
|
|
|
|
|
# add library targets
|
|
|
|
|
#############################################################################
|
2016-05-08 18:30:24 +03:00
|
|
|
|
2022-09-23 10:23:08 +03:00
|
|
|
add_library(${JSON_TARGET_NAME} INTERFACE)
|
|
|
|
|
add_library(${PROJECT_NAME}::${JSON_TARGET_NAME} ALIAS ${JSON_TARGET_NAME})
|
2019-03-28 16:22:48 +03:00
|
|
|
if (${CMAKE_VERSION} VERSION_LESS "3.8.0")
|
2022-09-23 10:23:08 +03:00
|
|
|
target_compile_features(${JSON_TARGET_NAME} INTERFACE cxx_range_for)
|
2019-01-16 16:21:49 +03:00
|
|
|
else()
|
2022-09-23 10:23:08 +03:00
|
|
|
target_compile_features(${JSON_TARGET_NAME} INTERFACE cxx_std_11)
|
2019-01-16 16:21:49 +03:00
|
|
|
endif()
|
2018-03-27 19:51:30 +03:00
|
|
|
|
2020-07-16 12:11:35 +03:00
|
|
|
target_compile_definitions(
|
2022-09-23 10:23:08 +03:00
|
|
|
${JSON_TARGET_NAME}
|
2020-07-16 12:11:35 +03:00
|
|
|
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(
|
2022-09-23 10:23:08 +03:00
|
|
|
${JSON_TARGET_NAME}
|
|
|
|
|
${JSON_SYSTEM_INCLUDE} INTERFACE
|
|
|
|
|
$<BUILD_INTERFACE:${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(
|
2022-09-23 10:23:08 +03:00
|
|
|
${JSON_TARGET_NAME}
|
2018-11-02 11:35:17 +03:00
|
|
|
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
|
|
|
|
2022-09-22 20:52:27 +03:00
|
|
|
#############################################################################
|
|
|
|
|
# add tests
|
|
|
|
|
#############################################################################
|
|
|
|
|
|
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
|
|
|
|
2022-09-24 12:57:52 +03:00
|
|
|
# add CI targets
|
|
|
|
|
if(JSON_CI)
|
|
|
|
|
include(json_ci)
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-09-22 20:52:27 +03:00
|
|
|
#############################################################################
|
2022-09-23 11:12:42 +03:00
|
|
|
# generate package configuration files
|
2022-09-22 20:52:27 +03:00
|
|
|
#############################################################################
|
|
|
|
|
|
2022-09-23 11:12:42 +03:00
|
|
|
# generate pkg-config file
|
|
|
|
|
configure_file(
|
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/pkg-config.pc.in"
|
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
|
|
|
|
|
)
|
|
|
|
|
|
2022-09-23 13:11:50 +03:00
|
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
|
|
|
|
|
|
# generate CMake module configuration file
|
|
|
|
|
configure_package_config_file(
|
2022-09-23 11:12:42 +03:00
|
|
|
${JSON_CMAKE_CONFIG_TEMPLATE}
|
|
|
|
|
${JSON_CMAKE_PROJECT_CONFIG_FILE}
|
2022-09-23 13:11:50 +03:00
|
|
|
INSTALL_DESTINATION ${JSON_CONFIG_INSTALL_DIR}
|
|
|
|
|
NO_SET_AND_CHECK_MACRO
|
2022-09-23 11:12:42 +03:00
|
|
|
)
|
|
|
|
|
|
2022-09-23 13:11:50 +03:00
|
|
|
# generate CMake module version file
|
|
|
|
|
if(CMAKE_VERSION VERSION_EQUAL "3.14" OR CMAKE_VERSION VERSION_GREATER "3.14")
|
|
|
|
|
write_basic_package_version_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"
|
|
|
|
|
${JSON_CMAKE_VERSION_CONFIG_FILE}
|
|
|
|
|
@ONLY
|
|
|
|
|
)
|
|
|
|
|
endif()
|
2022-09-23 11:12:42 +03:00
|
|
|
|
|
|
|
|
#############################################################################
|
|
|
|
|
# install files and targets
|
|
|
|
|
#############################################################################
|
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(
|
2022-09-23 10:23:08 +03:00
|
|
|
DIRECTORY ${JSON_INCLUDE_BUILD_DIR}
|
|
|
|
|
DESTINATION ${JSON_INCLUDE_INSTALL_DIR}
|
2018-11-02 12:15:27 +03:00
|
|
|
)
|
|
|
|
|
install(
|
2022-09-23 10:23:08 +03:00
|
|
|
FILES ${JSON_CMAKE_PROJECT_CONFIG_FILE} ${JSON_CMAKE_VERSION_CONFIG_FILE}
|
|
|
|
|
DESTINATION ${JSON_CONFIG_INSTALL_DIR}
|
2018-11-02 12:15:27 +03:00
|
|
|
)
|
|
|
|
|
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(
|
2022-09-23 10:23:08 +03:00
|
|
|
TARGETS ${JSON_TARGET_NAME}
|
2018-11-02 12:15:27 +03:00
|
|
|
NAMESPACE ${PROJECT_NAME}::
|
2022-09-23 10:23:08 +03:00
|
|
|
FILE ${JSON_CMAKE_PROJECT_TARGETS_FILE}
|
2018-11-02 12:15:27 +03:00
|
|
|
)
|
|
|
|
|
install(
|
2022-09-23 10:23:08 +03:00
|
|
|
TARGETS ${JSON_TARGET_NAME}
|
|
|
|
|
EXPORT ${JSON_TARGETS_EXPORT_NAME}
|
|
|
|
|
INCLUDES DESTINATION ${JSON_INCLUDE_INSTALL_DIR}
|
2018-11-02 12:15:27 +03:00
|
|
|
)
|
|
|
|
|
install(
|
2022-09-23 10:23:08 +03:00
|
|
|
EXPORT ${JSON_TARGETS_EXPORT_NAME}
|
2018-11-02 12:15:27 +03:00
|
|
|
NAMESPACE ${PROJECT_NAME}::
|
2022-09-23 10:23:08 +03:00
|
|
|
DESTINATION ${JSON_CONFIG_INSTALL_DIR}
|
2018-11-02 12:15:27 +03:00
|
|
|
)
|
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"
|
2022-09-23 10:23:08 +03:00
|
|
|
DESTINATION ${JSON_PKGCONFIG_INSTALL_DIR}
|
2019-08-09 00:36:27 +03:00
|
|
|
)
|
2021-05-15 21:09:15 +03:00
|
|
|
endif()
|
2022-09-22 14:47:31 +03:00
|
|
|
|
2022-09-22 20:52:27 +03:00
|
|
|
#############################################################################
|
|
|
|
|
# print feature summary
|
|
|
|
|
#############################################################################
|
|
|
|
|
|
2022-09-22 14:47:31 +03:00
|
|
|
include(json_summary)
|