Codechange: vendor the nlohmann-json library (#11290)
(cherry picked from commit ba67f39db6
)
# Conflicts:
# .github/workflows/ci-build.yml
# CMakeLists.txt
# COMPILING.md
# src/os/macosx/survey_osx.cpp
# src/os/windows/survey_win.cpp
# src/script/api/script_admin.cpp
# src/script/api/script_event_types.cpp
# src/tests/test_script_admin.cpp
pull/611/head
parent
af1150182a
commit
cf4cf5c08f
@ -1,21 +0,0 @@
|
||||
# nlohmann-json is a custom addition to the emscripten SDK, so it is possible
|
||||
# someone patched their SDK. Test out if the SDK supports nlohmann-json.
|
||||
include(CheckCXXSourceCompiles)
|
||||
set(CMAKE_REQUIRED_FLAGS "-sUSE_NLOHMANN_JSON=1")
|
||||
|
||||
check_cxx_source_compiles("
|
||||
#include <nlohmann/json.hpp>
|
||||
int main() { return 0; }"
|
||||
nlohmann_json_FOUND
|
||||
)
|
||||
|
||||
if (nlohmann_json_FOUND)
|
||||
add_library(nlohmann_json INTERFACE IMPORTED)
|
||||
set_target_properties(nlohmann_json PROPERTIES
|
||||
INTERFACE_COMPILE_OPTIONS "-sUSE_NLOHMANN_JSON=1"
|
||||
INTERFACE_LINK_LIBRARIES "-sUSE_NLOHMANN_JSON=1"
|
||||
)
|
||||
set(nlohmann_json_LIBRARY "nlohmann_json")
|
||||
else()
|
||||
message(WARNING "You are using an emscripten SDK without nlohmann-json support. Please apply 'emsdk-nlohmann_json.patch' to your local emsdk installation.")
|
||||
endif()
|
@ -1,93 +0,0 @@
|
||||
From 0edcedbea375e59f41df10acaee0c483d245751f Mon Sep 17 00:00:00 2001
|
||||
From: Patric Stout <truebrain@openttd.org>
|
||||
Date: Tue, 2 May 2023 21:48:08 +0200
|
||||
Subject: [PATCH] Add nlohmmann-json port
|
||||
|
||||
---
|
||||
src/settings.js | 4 ++++
|
||||
tools/ports/nlohmann_json.py | 46 ++++++++++++++++++++++++++++++++++++
|
||||
tools/settings.py | 1 +
|
||||
3 files changed, 51 insertions(+)
|
||||
create mode 100644 tools/ports/nlohmann_json.py
|
||||
|
||||
diff --git a/src/settings.js b/src/settings.js
|
||||
index f93140d..39f4366 100644
|
||||
--- a/src/settings.js
|
||||
+++ b/src/settings.js
|
||||
@@ -1483,6 +1483,10 @@ var USE_MPG123 = false;
|
||||
// [compile+link]
|
||||
var USE_FREETYPE = false;
|
||||
|
||||
+// 1 = use nlohmann-json from emscripten-ports
|
||||
+// [compile+link]
|
||||
+var USE_NLOHMANN_JSON = false;
|
||||
+
|
||||
// Specify the SDL_mixer version that is being linked against.
|
||||
// Doesn't *have* to match USE_SDL, but a good idea.
|
||||
// [compile+link]
|
||||
diff --git a/tools/ports/nlohmann_json.py b/tools/ports/nlohmann_json.py
|
||||
new file mode 100644
|
||||
index 0000000..9e44297
|
||||
--- /dev/null
|
||||
+++ b/tools/ports/nlohmann_json.py
|
||||
@@ -0,0 +1,46 @@
|
||||
+# Copyright 2023 The Emscripten Authors. All rights reserved.
|
||||
+# Emscripten is available under two separate licenses, the MIT license and the
|
||||
+# University of Illinois/NCSA Open Source License. Both these licenses can be
|
||||
+# found in the LICENSE file.
|
||||
+
|
||||
+import os
|
||||
+
|
||||
+TAG = '3.11.2'
|
||||
+HASH = '99d9e6d588cabe8913a37437f86acb5d4b8b98bce12423e633c11c13b61e6c7f92ef8f9a4e991baa590329ee2b5c09ca9db9894bee1e54bdd68e8d09d83cc245'
|
||||
+
|
||||
+
|
||||
+def needed(settings):
|
||||
+ return settings.USE_NLOHMANN_JSON
|
||||
+
|
||||
+
|
||||
+def get(ports, settings, shared):
|
||||
+ ports.fetch_project('nlohmann_json',
|
||||
+ f'https://github.com/nlohmann/json/releases/download/v{TAG}/include.zip',
|
||||
+ sha512hash=HASH)
|
||||
+
|
||||
+ def create(final):
|
||||
+ source_path = os.path.join(ports.get_dir(), 'nlohmann_json')
|
||||
+ source_path_include = os.path.join(source_path, 'include', 'nlohmann')
|
||||
+ ports.install_header_dir(source_path_include, 'nlohmann')
|
||||
+
|
||||
+ # write out a dummy cpp file, to create an empty library
|
||||
+ # this is needed as emscripten ports expect this, even if it is not used
|
||||
+ dummy_file = os.path.join(source_path, 'dummy.cpp')
|
||||
+ shared.safe_ensure_dirs(os.path.dirname(dummy_file))
|
||||
+ ports.write_file(dummy_file, 'static void dummy() {}')
|
||||
+
|
||||
+ ports.build_port(source_path, final, 'nlohmann_json', srcs=['dummy.cpp'])
|
||||
+
|
||||
+ return [shared.cache.get_lib('libnlohmann_json.a', create, what='port')]
|
||||
+
|
||||
+
|
||||
+def clear(ports, settings, shared):
|
||||
+ shared.cache.erase_lib('libnlohmann_json.a')
|
||||
+
|
||||
+
|
||||
+def process_args(ports):
|
||||
+ return []
|
||||
+
|
||||
+
|
||||
+def show():
|
||||
+ return 'nlohmann-json'
|
||||
diff --git a/tools/settings.py b/tools/settings.py
|
||||
index 10d6ca0..8536092 100644
|
||||
--- a/tools/settings.py
|
||||
+++ b/tools/settings.py
|
||||
@@ -47,6 +47,7 @@ PORTS_SETTINGS = {
|
||||
'USE_MPG123',
|
||||
'USE_GIFLIB',
|
||||
'USE_FREETYPE',
|
||||
+ 'USE_NLOHMANN_JSON',
|
||||
'SDL2_MIXER_FORMATS',
|
||||
'SDL2_IMAGE_FORMATS',
|
||||
'USE_SQLITE3',
|
||||
--
|
||||
2.34.1
|
@ -0,0 +1,3 @@
|
||||
add_files(
|
||||
json.hpp
|
||||
)
|
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2013-2022 Niels Lohmann
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue