Skip to content

Commit c29520f

Browse files
committed
#2482: lib: update json library to version 3.12.0
1 parent 836b38c commit c29520f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+19336
-17630
lines changed

lib/json/CMakeLists.txt

Lines changed: 81 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
cmake_minimum_required(VERSION 3.1...4.0)
1+
cmake_minimum_required(VERSION 3.5...4.0)
22

33
##
44
## PROJECT
55
## name and version
66
##
7-
project(nlohmann_json VERSION 3.9.1 LANGUAGES CXX)
7+
project(nlohmann_json VERSION 3.12.0 LANGUAGES CXX)
8+
9+
##
10+
## MAIN_PROJECT CHECK
11+
## determine if nlohmann_json is built as a subproject (using add_subdirectory) or if it is the main project
12+
##
13+
set(MAIN_PROJECT OFF)
14+
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
15+
set(MAIN_PROJECT ON)
16+
endif()
817

918
##
1019
## INCLUDE
1120
##
1221
##
22+
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
1323
include(ExternalProject)
1424

1525
##
@@ -21,26 +31,47 @@ if (POLICY CMP0077)
2131
cmake_policy(SET CMP0077 NEW)
2232
endif ()
2333

24-
option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ON)
25-
option(JSON_Install "Install CMake targets during install step." ON)
26-
option(JSON_MultipleHeaders "Use non-amalgamated version of the library." OFF)
27-
option(JSON_ImplicitConversions "Enable implicit conversions." ON)
34+
# VERSION_GREATER_EQUAL is not available in CMake 3.1
35+
if(${MAIN_PROJECT} AND (${CMAKE_VERSION} VERSION_EQUAL 3.13 OR ${CMAKE_VERSION} VERSION_GREATER 3.13))
36+
set(JSON_BuildTests_INIT ON)
37+
else()
38+
set(JSON_BuildTests_INIT OFF)
39+
endif()
40+
option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ${JSON_BuildTests_INIT})
41+
option(JSON_CI "Enable CI build targets." OFF)
42+
option(JSON_Diagnostics "Use extended diagnostic messages." OFF)
43+
option(JSON_Diagnostic_Positions "Enable diagnostic positions." OFF)
44+
option(JSON_GlobalUDLs "Place user-defined string literals in the global namespace." ON)
45+
option(JSON_ImplicitConversions "Enable implicit conversions." ON)
46+
option(JSON_DisableEnumSerialization "Disable default integer enum serialization." OFF)
47+
option(JSON_LegacyDiscardedValueComparison "Enable legacy discarded value comparison." OFF)
48+
option(JSON_Install "Install CMake targets during install step." ${MAIN_PROJECT})
49+
option(JSON_MultipleHeaders "Use non-amalgamated version of the library." ON)
50+
option(JSON_SystemInclude "Include as system headers (skip for clang-tidy)." OFF)
51+
52+
if (JSON_CI)
53+
include(ci)
54+
endif ()
2855

2956
##
3057
## CONFIGURATION
3158
##
3259
include(GNUInstallDirs)
3360

34-
set(NLOHMANN_JSON_TARGET_NAME ${PROJECT_NAME}-vt)
35-
set(NLOHMANN_JSON_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE INTERNAL "")
61+
if (NOT DEFINED NLOHMANN_JSON_TARGET_NAME)
62+
# Allow overriding the target name when using FetchContent / add_subdirectory.
63+
set(NLOHMANN_JSON_TARGET_NAME ${PROJECT_NAME}-vt)
64+
endif()
65+
66+
set(NLOHMANN_JSON_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}" CACHE INTERNAL "")
3667
set(NLOHMANN_JSON_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
3768
set(NLOHMANN_JSON_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
3869
set(NLOHMANN_JSON_CMAKE_CONFIG_TEMPLATE "cmake/config.cmake.in")
3970
set(NLOHMANN_JSON_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}")
4071
set(NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
4172
set(NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Config.cmake")
4273
set(NLOHMANN_JSON_CMAKE_PROJECT_TARGETS_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Targets.cmake")
43-
set(NLOHMANN_JSON_PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
74+
set(NLOHMANN_JSON_PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/pkgconfig")
4475

4576
if (JSON_MultipleHeaders)
4677
set(NLOHMANN_JSON_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/include/")
@@ -51,7 +82,31 @@ else()
5182
endif()
5283

5384
if (NOT JSON_ImplicitConversions)
54-
message(STATUS "Implicit conversions are disabled")
85+
message(STATUS "Implicit conversions are disabled (JSON_USE_IMPLICIT_CONVERSIONS=0)")
86+
endif()
87+
88+
if (JSON_DisableEnumSerialization)
89+
message(STATUS "Enum integer serialization is disabled (JSON_DISABLE_ENUM_SERIALIZATION=0)")
90+
endif()
91+
92+
if (JSON_LegacyDiscardedValueComparison)
93+
message(STATUS "Legacy discarded value comparison enabled (JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1)")
94+
endif()
95+
96+
if (JSON_Diagnostics)
97+
message(STATUS "Diagnostics enabled (JSON_DIAGNOSTICS=1)")
98+
endif()
99+
100+
if (JSON_Diagnostic_Positions)
101+
message(STATUS "Diagnostic positions enabled (JSON_DIAGNOSTIC_POSITIONS=1)")
102+
endif()
103+
104+
if (NOT JSON_GlobalUDLs)
105+
message(STATUS "User-defined string literals are not put in the global namespace (JSON_USE_GLOBAL_UDLS=0)")
106+
endif()
107+
108+
if (JSON_SystemInclude)
109+
set(NLOHMANN_JSON_SYSTEM_INCLUDE "SYSTEM")
55110
endif()
56111

57112
##
@@ -69,14 +124,19 @@ endif()
69124
target_compile_definitions(
70125
${NLOHMANN_JSON_TARGET_NAME}
71126
INTERFACE
72-
JSON_USE_IMPLICIT_CONVERSIONS=$<BOOL:${JSON_ImplicitConversions}>
127+
$<$<NOT:$<BOOL:${JSON_GlobalUDLs}>>:JSON_USE_GLOBAL_UDLS=0>
128+
$<$<NOT:$<BOOL:${JSON_ImplicitConversions}>>:JSON_USE_IMPLICIT_CONVERSIONS=0>
129+
$<$<BOOL:${JSON_DisableEnumSerialization}>:JSON_DISABLE_ENUM_SERIALIZATION=1>
130+
$<$<BOOL:${JSON_Diagnostics}>:JSON_DIAGNOSTICS=1>
131+
$<$<BOOL:${JSON_Diagnostic_Positions}>:JSON_DIAGNOSTIC_POSITIONS=1>
132+
$<$<BOOL:${JSON_LegacyDiscardedValueComparison}>:JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1>
73133
)
74134

75135
target_include_directories(
76136
${NLOHMANN_JSON_TARGET_NAME}
77-
INTERFACE
137+
${NLOHMANN_JSON_SYSTEM_INCLUDE} INTERFACE
78138
$<BUILD_INTERFACE:${NLOHMANN_JSON_INCLUDE_BUILD_DIR}>
79-
$<INSTALL_INTERFACE:include>
139+
$<INSTALL_INTERFACE:${NLOHMANN_JSON_INCLUDE_INSTALL_DIR}>
80140
)
81141

82142
## add debug view definition file for msvc (natvis)
@@ -93,19 +153,19 @@ endif()
93153

94154
# Install a pkg-config file, so other tools can find this.
95155
CONFIGURE_FILE(
96-
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/pkg-config.pc.in"
97-
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
156+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/pkg-config.pc.in"
157+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
158+
@ONLY
98159
)
99160

100161
##
101162
## TESTS
102163
## create and configure the unit test target
103164
##
104-
include(CTest) #adds option BUILD_TESTING (default ON)
105-
106-
if(BUILD_TESTING AND JSON_BuildTests)
165+
if (JSON_BuildTests)
166+
include(CTest)
107167
enable_testing()
108-
add_subdirectory(test)
168+
add_subdirectory(tests)
109169
endif()
110170

111171
##
@@ -141,7 +201,7 @@ if(JSON_Install)
141201
FILES ${NLOHMANN_NATVIS_FILE}
142202
DESTINATION .
143203
)
144-
endif()
204+
endif()
145205
export(
146206
TARGETS ${NLOHMANN_JSON_TARGET_NAME}
147207
NAMESPACE ${PROJECT_NAME}::
@@ -161,4 +221,5 @@ endif()
161221
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
162222
DESTINATION ${NLOHMANN_JSON_PKGCONFIG_INSTALL_DIR}
163223
)
224+
include(CPack)
164225
endif()

0 commit comments

Comments
 (0)