Skip to content

Commit f85a1d5

Browse files
github-actions[bot]skyzh
authored andcommitted
vendor json
1 parent 4373699 commit f85a1d5

Some content is hidden

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

52 files changed

+49763
-0
lines changed

third_party/json/CMakeLists.txt

+209
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
3+
##
4+
## PROJECT
5+
## name and version
6+
##
7+
project(nlohmann_json VERSION 3.11.2 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()
17+
18+
##
19+
## INCLUDE
20+
##
21+
##
22+
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
23+
include(ExternalProject)
24+
25+
##
26+
## OPTIONS
27+
##
28+
29+
if (POLICY CMP0077)
30+
# Allow CMake 3.13+ to override options when using FetchContent / add_subdirectory.
31+
cmake_policy(SET CMP0077 NEW)
32+
endif ()
33+
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_GlobalUDLs "Place use-defined string literals in the global namespace." ON)
44+
option(JSON_ImplicitConversions "Enable implicit conversions." ON)
45+
option(JSON_DisableEnumSerialization "Disable default integer enum serialization." OFF)
46+
option(JSON_LegacyDiscardedValueComparison "Enable legacy discarded value comparison." OFF)
47+
option(JSON_Install "Install CMake targets during install step." ${MAIN_PROJECT})
48+
option(JSON_MultipleHeaders "Use non-amalgamated version of the library." ON)
49+
option(JSON_SystemInclude "Include as system headers (skip for clang-tidy)." OFF)
50+
51+
if (JSON_CI)
52+
include(ci)
53+
endif ()
54+
55+
##
56+
## CONFIGURATION
57+
##
58+
include(GNUInstallDirs)
59+
60+
set(NLOHMANN_JSON_TARGET_NAME ${PROJECT_NAME})
61+
set(NLOHMANN_JSON_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}" CACHE INTERNAL "")
62+
set(NLOHMANN_JSON_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
63+
set(NLOHMANN_JSON_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
64+
set(NLOHMANN_JSON_CMAKE_CONFIG_TEMPLATE "cmake/config.cmake.in")
65+
set(NLOHMANN_JSON_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}")
66+
set(NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
67+
set(NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Config.cmake")
68+
set(NLOHMANN_JSON_CMAKE_PROJECT_TARGETS_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Targets.cmake")
69+
set(NLOHMANN_JSON_PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/pkgconfig")
70+
71+
if (JSON_MultipleHeaders)
72+
set(NLOHMANN_JSON_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/include/")
73+
message(STATUS "Using the multi-header code from ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}")
74+
else()
75+
set(NLOHMANN_JSON_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/single_include/")
76+
message(STATUS "Using the single-header code from ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}")
77+
endif()
78+
79+
if (NOT JSON_ImplicitConversions)
80+
message(STATUS "Implicit conversions are disabled")
81+
endif()
82+
83+
if (JSON_DisableEnumSerialization)
84+
message(STATUS "Enum integer serialization is disabled")
85+
endif()
86+
87+
if (JSON_LegacyDiscardedValueComparison)
88+
message(STATUS "Legacy discarded value comparison enabled")
89+
endif()
90+
91+
if (JSON_Diagnostics)
92+
message(STATUS "Diagnostics enabled")
93+
endif()
94+
95+
if (JSON_SystemInclude)
96+
set(NLOHMANN_JSON_SYSTEM_INCLUDE "SYSTEM")
97+
endif()
98+
99+
##
100+
## TARGET
101+
## create target and add include path
102+
##
103+
add_library(${NLOHMANN_JSON_TARGET_NAME} INTERFACE)
104+
add_library(${PROJECT_NAME}::${NLOHMANN_JSON_TARGET_NAME} ALIAS ${NLOHMANN_JSON_TARGET_NAME})
105+
if (${CMAKE_VERSION} VERSION_LESS "3.8.0")
106+
target_compile_features(${NLOHMANN_JSON_TARGET_NAME} INTERFACE cxx_range_for)
107+
else()
108+
target_compile_features(${NLOHMANN_JSON_TARGET_NAME} INTERFACE cxx_std_11)
109+
endif()
110+
111+
target_compile_definitions(
112+
${NLOHMANN_JSON_TARGET_NAME}
113+
INTERFACE
114+
$<$<NOT:$<BOOL:${JSON_GlobalUDLs}>>:JSON_USE_GLOBAL_UDLS=0>
115+
$<$<NOT:$<BOOL:${JSON_ImplicitConversions}>>:JSON_USE_IMPLICIT_CONVERSIONS=0>
116+
$<$<BOOL:${JSON_DisableEnumSerialization}>:JSON_DISABLE_ENUM_SERIALIZATION=1>
117+
$<$<BOOL:${JSON_Diagnostics}>:JSON_DIAGNOSTICS=1>
118+
$<$<BOOL:${JSON_LegacyDiscardedValueComparison}>:JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1>
119+
)
120+
121+
target_include_directories(
122+
${NLOHMANN_JSON_TARGET_NAME}
123+
${NLOHMANN_JSON_SYSTEM_INCLUDE} INTERFACE
124+
$<BUILD_INTERFACE:${NLOHMANN_JSON_INCLUDE_BUILD_DIR}>
125+
$<INSTALL_INTERFACE:include>
126+
)
127+
128+
## add debug view definition file for msvc (natvis)
129+
if (MSVC)
130+
set(NLOHMANN_ADD_NATVIS TRUE)
131+
set(NLOHMANN_NATVIS_FILE "nlohmann_json.natvis")
132+
target_sources(
133+
${NLOHMANN_JSON_TARGET_NAME}
134+
INTERFACE
135+
$<INSTALL_INTERFACE:${NLOHMANN_NATVIS_FILE}>
136+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${NLOHMANN_NATVIS_FILE}>
137+
)
138+
endif()
139+
140+
# Install a pkg-config file, so other tools can find this.
141+
CONFIGURE_FILE(
142+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/pkg-config.pc.in"
143+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
144+
)
145+
146+
##
147+
## TESTS
148+
## create and configure the unit test target
149+
##
150+
if (JSON_BuildTests)
151+
include(CTest)
152+
enable_testing()
153+
add_subdirectory(tests)
154+
endif()
155+
156+
##
157+
## INSTALL
158+
## install header files, generate and install cmake config files for find_package()
159+
##
160+
include(CMakePackageConfigHelpers)
161+
# use a custom package version config file instead of
162+
# write_basic_package_version_file to ensure that it's architecture-independent
163+
# https://github.com/nlohmann/json/issues/1697
164+
configure_file(
165+
"cmake/nlohmann_jsonConfigVersion.cmake.in"
166+
${NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE}
167+
@ONLY
168+
)
169+
configure_file(
170+
${NLOHMANN_JSON_CMAKE_CONFIG_TEMPLATE}
171+
${NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE}
172+
@ONLY
173+
)
174+
175+
if(JSON_Install)
176+
install(
177+
DIRECTORY ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}
178+
DESTINATION ${NLOHMANN_JSON_INCLUDE_INSTALL_DIR}
179+
)
180+
install(
181+
FILES ${NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE} ${NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE}
182+
DESTINATION ${NLOHMANN_JSON_CONFIG_INSTALL_DIR}
183+
)
184+
if (NLOHMANN_ADD_NATVIS)
185+
install(
186+
FILES ${NLOHMANN_NATVIS_FILE}
187+
DESTINATION .
188+
)
189+
endif()
190+
export(
191+
TARGETS ${NLOHMANN_JSON_TARGET_NAME}
192+
NAMESPACE ${PROJECT_NAME}::
193+
FILE ${NLOHMANN_JSON_CMAKE_PROJECT_TARGETS_FILE}
194+
)
195+
install(
196+
TARGETS ${NLOHMANN_JSON_TARGET_NAME}
197+
EXPORT ${NLOHMANN_JSON_TARGETS_EXPORT_NAME}
198+
INCLUDES DESTINATION ${NLOHMANN_JSON_INCLUDE_INSTALL_DIR}
199+
)
200+
install(
201+
EXPORT ${NLOHMANN_JSON_TARGETS_EXPORT_NAME}
202+
NAMESPACE ${PROJECT_NAME}::
203+
DESTINATION ${NLOHMANN_JSON_CONFIG_INSTALL_DIR}
204+
)
205+
install(
206+
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
207+
DESTINATION ${NLOHMANN_JSON_PKGCONFIG_INSTALL_DIR}
208+
)
209+
endif()

third_party/json/LICENSE.MIT

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2013-2022 Niels Lohmann
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
include(FindPackageHandleStandardArgs)
2+
set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG ${CMAKE_CURRENT_LIST_FILE})
3+
find_package_handle_standard_args(@PROJECT_NAME@ CONFIG_MODE)
4+
5+
if(NOT TARGET @PROJECT_NAME@::@NLOHMANN_JSON_TARGET_NAME@)
6+
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
7+
if((NOT TARGET @NLOHMANN_JSON_TARGET_NAME@) AND
8+
(NOT @PROJECT_NAME@_FIND_VERSION OR
9+
@PROJECT_NAME@_FIND_VERSION VERSION_LESS 3.2.0))
10+
add_library(@NLOHMANN_JSON_TARGET_NAME@ INTERFACE IMPORTED)
11+
set_target_properties(@NLOHMANN_JSON_TARGET_NAME@ PROPERTIES
12+
INTERFACE_LINK_LIBRARIES @PROJECT_NAME@::@NLOHMANN_JSON_TARGET_NAME@
13+
)
14+
endif()
15+
endif()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This is essentially cmake's BasicConfigVersion-SameMajorVersion.cmake.in but
2+
# without the 32/64-bit check. Since json is a header-only library, it doesn't
3+
# matter if it was built on a different platform than what it is used on (see
4+
# https://github.com/nlohmann/json/issues/1697).
5+
set(PACKAGE_VERSION "@PROJECT_VERSION@")
6+
7+
if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
8+
set(PACKAGE_VERSION_COMPATIBLE FALSE)
9+
else()
10+
11+
if(PACKAGE_FIND_VERSION_MAJOR STREQUAL "@PROJECT_VERSION_MAJOR@")
12+
set(PACKAGE_VERSION_COMPATIBLE TRUE)
13+
else()
14+
set(PACKAGE_VERSION_COMPATIBLE FALSE)
15+
endif()
16+
17+
if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
18+
set(PACKAGE_VERSION_EXACT TRUE)
19+
endif()
20+
endif()
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Name: ${PROJECT_NAME}
2+
Description: JSON for Modern C++
3+
Version: ${PROJECT_VERSION}
4+
Cflags: -I${CMAKE_INSTALL_FULL_INCLUDEDIR}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// __ _____ _____ _____
2+
// __| | __| | | | JSON for Modern C++
3+
// | | |__ | | | | | | version 3.11.2
4+
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
5+
//
6+
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
7+
// SPDX-License-Identifier: MIT
8+
9+
#pragma once
10+
11+
#include <utility>
12+
13+
#include <nlohmann/detail/abi_macros.hpp>
14+
#include <nlohmann/detail/conversions/from_json.hpp>
15+
#include <nlohmann/detail/conversions/to_json.hpp>
16+
#include <nlohmann/detail/meta/identity_tag.hpp>
17+
18+
NLOHMANN_JSON_NAMESPACE_BEGIN
19+
20+
/// @sa https://json.nlohmann.me/api/adl_serializer/
21+
template<typename ValueType, typename>
22+
struct adl_serializer
23+
{
24+
/// @brief convert a JSON value to any value type
25+
/// @sa https://json.nlohmann.me/api/adl_serializer/from_json/
26+
template<typename BasicJsonType, typename TargetType = ValueType>
27+
static auto from_json(BasicJsonType && j, TargetType& val) noexcept(
28+
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
29+
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void())
30+
{
31+
::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
32+
}
33+
34+
/// @brief convert a JSON value to any value type
35+
/// @sa https://json.nlohmann.me/api/adl_serializer/from_json/
36+
template<typename BasicJsonType, typename TargetType = ValueType>
37+
static auto from_json(BasicJsonType && j) noexcept(
38+
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})))
39+
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))
40+
{
41+
return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {});
42+
}
43+
44+
/// @brief convert any value type to a JSON value
45+
/// @sa https://json.nlohmann.me/api/adl_serializer/to_json/
46+
template<typename BasicJsonType, typename TargetType = ValueType>
47+
static auto to_json(BasicJsonType& j, TargetType && val) noexcept(
48+
noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
49+
-> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void())
50+
{
51+
::nlohmann::to_json(j, std::forward<TargetType>(val));
52+
}
53+
};
54+
55+
NLOHMANN_JSON_NAMESPACE_END

0 commit comments

Comments
 (0)