mirror of
https://github.com/nlohmann/json.git
synced 2024-11-23 22:19:02 +08:00
a97041a98f
Some checks failed
Code scanning - action / CodeQL-Build (push) Has been cancelled
macOS / macos-12 (13.1) (push) Has been cancelled
macOS / macos-12 (13.2.1) (push) Has been cancelled
macOS / macos-12 (13.3.1) (push) Has been cancelled
macOS / macos-12 (13.4.1) (push) Has been cancelled
macOS / macos-12 (14.0) (push) Has been cancelled
macOS / macos-12 (14.0.1) (push) Has been cancelled
macOS / macos-12 (14.1) (push) Has been cancelled
macOS / macos-13 (14.2) (push) Has been cancelled
macOS / macos-13 (14.3) (push) Has been cancelled
macOS / macos-13 (14.3.1) (push) Has been cancelled
macOS / macos-13 (15.0.1) (push) Has been cancelled
macOS / macos-13 (15.1) (push) Has been cancelled
macOS / macos-13 (15.2) (push) Has been cancelled
macOS / macos-14 (15.3) (push) Has been cancelled
macOS / macos-14 (15.4) (push) Has been cancelled
macOS / macos-15 (16.0) (push) Has been cancelled
macOS / macos-15 (16.1) (push) Has been cancelled
macOS / xcode_standards (11) (push) Has been cancelled
macOS / xcode_standards (14) (push) Has been cancelled
macOS / xcode_standards (17) (push) Has been cancelled
macOS / xcode_standards (20) (push) Has been cancelled
macOS / xcode_standards (23) (push) Has been cancelled
Ubuntu / ci_test_clang (push) Has been cancelled
Ubuntu / ci_test_gcc (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_cppcheck) (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_infer) (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_single_binaries) (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_test_amalgamation) (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_test_single_header) (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_test_valgrind) (push) Has been cancelled
Ubuntu / ci_static_analysis_ubuntu (ci_cpplint) (push) Has been cancelled
Ubuntu / ci_static_analysis_ubuntu (ci_non_git_tests) (push) Has been cancelled
Ubuntu / ci_static_analysis_ubuntu (ci_offline_testdata) (push) Has been cancelled
Ubuntu / ci_static_analysis_ubuntu (ci_reproducible_tests) (push) Has been cancelled
Ubuntu / ci_static_analysis_clang (ci_clang_analyze) (push) Has been cancelled
Ubuntu / ci_static_analysis_clang (ci_clang_tidy) (push) Has been cancelled
Ubuntu / ci_static_analysis_clang (ci_test_clang_sanitizer) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_cmake_flags) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_test_diagnostics) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_test_legacycomparison) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_test_noexceptions) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_test_noglobaludls) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_test_noimplicitconversions) (push) Has been cancelled
Ubuntu / ci_test_coverage (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc_old (4.8) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc_old (4.9) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc_old (5) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc_old (6) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (10) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (11) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (12) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (13) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (14) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (7) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (8) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (9) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (latest) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (10) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (11) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (12) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (13) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (14) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (15-bullseye) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (16) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (17) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (18) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (19) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (3.5) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (3.6) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (3.7) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (3.8) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (3.9) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (4) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (5) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (6) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (7) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (8) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (9) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (latest) (push) Has been cancelled
Ubuntu / ci_test_compilers (g++-4.8) (push) Has been cancelled
Ubuntu / ci_test_standards_gcc (11) (push) Has been cancelled
Ubuntu / ci_test_standards_gcc (14) (push) Has been cancelled
Ubuntu / ci_test_standards_gcc (17) (push) Has been cancelled
Ubuntu / ci_test_standards_gcc (20) (push) Has been cancelled
Ubuntu / ci_test_standards_gcc (23) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (11, libcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (11, libstdcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (14, libcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (14, libstdcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (17, libcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (17, libstdcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (20, libcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (20, libstdcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (23, libcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (23, libstdcxx) (push) Has been cancelled
Ubuntu / ci_cuda_example (push) Has been cancelled
Ubuntu / ci_icpc (push) Has been cancelled
Ubuntu / ci_reuse_compliance (push) Has been cancelled
Ubuntu / ci_test_documentation (ci_test_api_documentation) (push) Has been cancelled
Ubuntu / ci_test_documentation (ci_test_examples) (push) Has been cancelled
Windows / mingw (x64) (push) Has been cancelled
Windows / mingw (x86) (push) Has been cancelled
Windows / msvc2019 (Win32, Debug) (push) Has been cancelled
Windows / msvc2019 (Win32, Release) (push) Has been cancelled
Windows / msvc2019 (x64, Debug) (push) Has been cancelled
Windows / msvc2019 (x64, Release) (push) Has been cancelled
Windows / msvc2019_latest (push) Has been cancelled
Windows / msvc2022 (Win32, Debug) (push) Has been cancelled
Windows / msvc2022 (Win32, Release) (push) Has been cancelled
Windows / msvc2022 (x64, Debug) (push) Has been cancelled
Windows / msvc2022 (x64, Release) (push) Has been cancelled
Windows / msvc2022_latest (push) Has been cancelled
Windows / clang (11) (push) Has been cancelled
Windows / clang (12) (push) Has been cancelled
Windows / clang (13) (push) Has been cancelled
Windows / clang (14) (push) Has been cancelled
Windows / clang (15) (push) Has been cancelled
Windows / clang-cl-11 (Win32) (push) Has been cancelled
Windows / clang-cl-11 (x64) (push) Has been cancelled
* ✅ skip enum tests when JSON_DisableEnumSerialization=ON * ✅ skip enum tests when JSON_DisableEnumSerialization=ON
219 lines
7.3 KiB
CMake
219 lines
7.3 KiB
CMake
cmake_minimum_required(VERSION 3.1...3.14)
|
|
|
|
##
|
|
## PROJECT
|
|
## name and version
|
|
##
|
|
project(nlohmann_json VERSION 3.11.3 LANGUAGES CXX)
|
|
|
|
##
|
|
## MAIN_PROJECT CHECK
|
|
## determine if nlohmann_json is built as a subproject (using add_subdirectory) or if it is the main project
|
|
##
|
|
set(MAIN_PROJECT OFF)
|
|
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
|
set(MAIN_PROJECT ON)
|
|
endif()
|
|
|
|
##
|
|
## INCLUDE
|
|
##
|
|
##
|
|
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
|
|
include(ExternalProject)
|
|
|
|
##
|
|
## OPTIONS
|
|
##
|
|
|
|
if (POLICY CMP0077)
|
|
# Allow CMake 3.13+ to override options when using FetchContent / add_subdirectory.
|
|
cmake_policy(SET CMP0077 NEW)
|
|
endif ()
|
|
|
|
# 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()
|
|
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)
|
|
option(JSON_GlobalUDLs "Place user-defined string literals in the global namespace." ON)
|
|
option(JSON_ImplicitConversions "Enable implicit conversions." ON)
|
|
option(JSON_DisableEnumSerialization "Disable default integer enum serialization." OFF)
|
|
option(JSON_LegacyDiscardedValueComparison "Enable legacy discarded value comparison." OFF)
|
|
option(JSON_Install "Install CMake targets during install step." ${MAIN_PROJECT})
|
|
option(JSON_MultipleHeaders "Use non-amalgamated version of the library." ON)
|
|
option(JSON_SystemInclude "Include as system headers (skip for clang-tidy)." OFF)
|
|
|
|
if (JSON_CI)
|
|
include(ci)
|
|
endif ()
|
|
|
|
##
|
|
## CONFIGURATION
|
|
##
|
|
include(GNUInstallDirs)
|
|
|
|
if (NOT DEFINED NLOHMANN_JSON_TARGET_NAME)
|
|
# Allow overriding the target name when using FetchContent / add_subdirectory.
|
|
set(NLOHMANN_JSON_TARGET_NAME ${PROJECT_NAME})
|
|
endif()
|
|
|
|
set(NLOHMANN_JSON_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}" CACHE INTERNAL "")
|
|
set(NLOHMANN_JSON_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
|
|
set(NLOHMANN_JSON_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
|
|
set(NLOHMANN_JSON_CMAKE_CONFIG_TEMPLATE "cmake/config.cmake.in")
|
|
set(NLOHMANN_JSON_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}")
|
|
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")
|
|
set(NLOHMANN_JSON_CMAKE_PROJECT_TARGETS_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Targets.cmake")
|
|
set(NLOHMANN_JSON_PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/pkgconfig")
|
|
|
|
if (JSON_MultipleHeaders)
|
|
set(NLOHMANN_JSON_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/include/")
|
|
message(STATUS "Using the multi-header code from ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}")
|
|
else()
|
|
set(NLOHMANN_JSON_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/single_include/")
|
|
message(STATUS "Using the single-header code from ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}")
|
|
endif()
|
|
|
|
if (NOT JSON_ImplicitConversions)
|
|
message(STATUS "Implicit conversions are disabled")
|
|
endif()
|
|
|
|
if (JSON_DisableEnumSerialization)
|
|
message(STATUS "Enum integer serialization is disabled")
|
|
endif()
|
|
|
|
if (JSON_LegacyDiscardedValueComparison)
|
|
message(STATUS "Legacy discarded value comparison enabled")
|
|
endif()
|
|
|
|
if (JSON_Diagnostics)
|
|
message(STATUS "Diagnostics enabled")
|
|
endif()
|
|
|
|
if (NOT JSON_GlobalUDLs)
|
|
message(STATUS "User-defined string literals are not put in the global namespace")
|
|
endif()
|
|
|
|
if (JSON_SystemInclude)
|
|
set(NLOHMANN_JSON_SYSTEM_INCLUDE "SYSTEM")
|
|
endif()
|
|
|
|
##
|
|
## TARGET
|
|
## create target and add include path
|
|
##
|
|
add_library(${NLOHMANN_JSON_TARGET_NAME} INTERFACE)
|
|
add_library(${PROJECT_NAME}::${NLOHMANN_JSON_TARGET_NAME} ALIAS ${NLOHMANN_JSON_TARGET_NAME})
|
|
if (${CMAKE_VERSION} VERSION_LESS "3.8.0")
|
|
target_compile_features(${NLOHMANN_JSON_TARGET_NAME} INTERFACE cxx_range_for)
|
|
else()
|
|
target_compile_features(${NLOHMANN_JSON_TARGET_NAME} INTERFACE cxx_std_11)
|
|
endif()
|
|
|
|
target_compile_definitions(
|
|
${NLOHMANN_JSON_TARGET_NAME}
|
|
INTERFACE
|
|
$<$<NOT:$<BOOL:${JSON_GlobalUDLs}>>:JSON_USE_GLOBAL_UDLS=0>
|
|
$<$<NOT:$<BOOL:${JSON_ImplicitConversions}>>:JSON_USE_IMPLICIT_CONVERSIONS=0>
|
|
$<$<BOOL:${JSON_DisableEnumSerialization}>:JSON_DISABLE_ENUM_SERIALIZATION=1>
|
|
$<$<BOOL:${JSON_Diagnostics}>:JSON_DIAGNOSTICS=1>
|
|
$<$<BOOL:${JSON_LegacyDiscardedValueComparison}>:JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1>
|
|
)
|
|
|
|
target_include_directories(
|
|
${NLOHMANN_JSON_TARGET_NAME}
|
|
${NLOHMANN_JSON_SYSTEM_INCLUDE} INTERFACE
|
|
$<BUILD_INTERFACE:${NLOHMANN_JSON_INCLUDE_BUILD_DIR}>
|
|
$<INSTALL_INTERFACE:${NLOHMANN_JSON_INCLUDE_INSTALL_DIR}>
|
|
)
|
|
|
|
## add debug view definition file for msvc (natvis)
|
|
if (MSVC)
|
|
set(NLOHMANN_ADD_NATVIS TRUE)
|
|
set(NLOHMANN_NATVIS_FILE "nlohmann_json.natvis")
|
|
target_sources(
|
|
${NLOHMANN_JSON_TARGET_NAME}
|
|
INTERFACE
|
|
$<INSTALL_INTERFACE:${NLOHMANN_NATVIS_FILE}>
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${NLOHMANN_NATVIS_FILE}>
|
|
)
|
|
endif()
|
|
|
|
# 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"
|
|
)
|
|
|
|
##
|
|
## TESTS
|
|
## create and configure the unit test target
|
|
##
|
|
if (JSON_BuildTests)
|
|
include(CTest)
|
|
enable_testing()
|
|
add_subdirectory(tests)
|
|
endif()
|
|
|
|
##
|
|
## INSTALL
|
|
## install header files, generate and install cmake config files for find_package()
|
|
##
|
|
include(CMakePackageConfigHelpers)
|
|
# 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"
|
|
${NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE}
|
|
@ONLY
|
|
)
|
|
configure_file(
|
|
${NLOHMANN_JSON_CMAKE_CONFIG_TEMPLATE}
|
|
${NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE}
|
|
@ONLY
|
|
)
|
|
|
|
if(JSON_Install)
|
|
install(
|
|
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 .
|
|
)
|
|
endif()
|
|
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}
|
|
)
|
|
install(
|
|
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
|
|
DESTINATION ${NLOHMANN_JSON_PKGCONFIG_INSTALL_DIR}
|
|
)
|
|
include(CPack)
|
|
endif()
|