mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: vendor the nlohmann-json library (#11290)
This commit is contained in:
parent
41de0d46f3
commit
ba67f39db6
|
@ -32,11 +32,10 @@ jobs:
|
|||
path: /emsdk/upstream/emscripten/cache
|
||||
key: 3.1.42-${{ runner.os }}
|
||||
|
||||
- name: Patch Emscripten to support LZMA and nlohmann-json
|
||||
- name: Patch Emscripten to support LZMA
|
||||
run: |
|
||||
cd /emsdk/upstream/emscripten
|
||||
patch -p1 < ${GITHUB_WORKSPACE}/os/emscripten/emsdk-liblzma.patch
|
||||
patch -p1 < ${GITHUB_WORKSPACE}/os/emscripten/emsdk-nlohmann-json.patch
|
||||
|
||||
- name: Build (host tools)
|
||||
run: |
|
||||
|
@ -118,7 +117,6 @@ jobs:
|
|||
libicu-dev \
|
||||
liblzma-dev \
|
||||
liblzo2-dev \
|
||||
nlohmann-json3-dev \
|
||||
${{ matrix.libraries }} \
|
||||
zlib1g-dev \
|
||||
# EOF
|
||||
|
@ -215,7 +213,6 @@ jobs:
|
|||
liblzma \
|
||||
libpng \
|
||||
lzo \
|
||||
nlohmann-json \
|
||||
zlib \
|
||||
# EOF
|
||||
|
||||
|
@ -300,7 +297,6 @@ jobs:
|
|||
liblzma \
|
||||
libpng \
|
||||
lzo \
|
||||
nlohmann-json \
|
||||
zlib \
|
||||
# EOF
|
||||
|
||||
|
@ -387,7 +383,6 @@ jobs:
|
|||
mingw-w64-${{ matrix.arch }}-libpng
|
||||
mingw-w64-${{ matrix.arch }}-lld
|
||||
mingw-w64-${{ matrix.arch }}-ninja
|
||||
mingw-w64-${{ matrix.arch }}-nlohmann-json
|
||||
|
||||
- name: Install OpenGFX
|
||||
shell: bash
|
||||
|
|
|
@ -40,11 +40,10 @@ jobs:
|
|||
path: /emsdk/upstream/emscripten/cache
|
||||
key: 3.1.42-${{ runner.os }}
|
||||
|
||||
- name: Patch Emscripten to support LZMA and nlohmann_json
|
||||
- name: Patch Emscripten to support LZMA
|
||||
run: |
|
||||
cd /emsdk/upstream/emscripten
|
||||
patch -p1 < ${GITHUB_WORKSPACE}/os/emscripten/emsdk-liblzma.patch
|
||||
patch -p1 < ${GITHUB_WORKSPACE}/os/emscripten/emsdk-nlohmann-json.patch
|
||||
|
||||
- name: Build (host tools)
|
||||
run: |
|
||||
|
|
|
@ -130,7 +130,6 @@ jobs:
|
|||
liblzma \
|
||||
libpng \
|
||||
lzo \
|
||||
nlohmann-json \
|
||||
sdl2 \
|
||||
zlib \
|
||||
# EOF
|
||||
|
|
|
@ -75,8 +75,6 @@ jobs:
|
|||
libpng:arm64-osx \
|
||||
lzo:x64-osx \
|
||||
lzo:arm64-osx \
|
||||
nlohmann-json:x64-osx \
|
||||
nlohmann-json:arm64-osx \
|
||||
zlib:x64-osx \
|
||||
zlib:arm64-osx \
|
||||
# EOF
|
||||
|
|
|
@ -80,7 +80,6 @@ jobs:
|
|||
liblzma \
|
||||
libpng \
|
||||
lzo \
|
||||
nlohmann-json \
|
||||
zlib \
|
||||
# EOF
|
||||
|
||||
|
|
|
@ -119,8 +119,6 @@ endif()
|
|||
set(CMAKE_THREAD_PREFER_PTHREAD YES)
|
||||
# Make sure we have Threads available.
|
||||
find_package(Threads REQUIRED)
|
||||
# nlohmann is used for all our JSON needs.
|
||||
find_package(nlohmann_json REQUIRED)
|
||||
|
||||
find_package(ZLIB)
|
||||
find_package(LibLZMA)
|
||||
|
@ -310,7 +308,6 @@ link_package(PNG TARGET PNG::PNG ENCOURAGED)
|
|||
link_package(ZLIB TARGET ZLIB::ZLIB ENCOURAGED)
|
||||
link_package(LIBLZMA TARGET LibLZMA::LibLZMA ENCOURAGED)
|
||||
link_package(LZO)
|
||||
link_package(nlohmann_json)
|
||||
|
||||
if(NOT WIN32 AND NOT EMSCRIPTEN)
|
||||
link_package(CURL ENCOURAGED)
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
OpenTTD makes use of the following external libraries:
|
||||
|
||||
- (required) nlohmann-json: JSON handling
|
||||
- (encouraged) breakpad: creates minidumps on crash
|
||||
- (encouraged) zlib: (de)compressing of old (0.3.0-1.0.5) savegames, content downloads,
|
||||
heightmaps
|
||||
|
@ -55,14 +54,13 @@ the `static` versions, and OpenTTD currently needs the following dependencies:
|
|||
- liblzma
|
||||
- libpng
|
||||
- lzo
|
||||
- nlohmann-json
|
||||
- zlib
|
||||
|
||||
To install both the x64 (64bit) and x86 (32bit) variants (though only one is necessary), you can use:
|
||||
|
||||
```ps
|
||||
.\vcpkg install breakpad:x64-windows-static liblzma:x64-windows-static libpng:x64-windows-static lzo:x64-windows-static nlohmann-json:x64-windows-static zlib:x64-windows-static
|
||||
.\vcpkg install breakpad:x86-windows-static liblzma:x86-windows-static libpng:x86-windows-static lzo:x86-windows-static nlohmann-json:x86-windows-static zlib:x86-windows-static
|
||||
.\vcpkg install breakpad:x64-windows-static liblzma:x64-windows-static libpng:x64-windows-static lzo:x64-windows-static zlib:x64-windows-static
|
||||
.\vcpkg install breakpad:x86-windows-static liblzma:x86-windows-static libpng:x86-windows-static lzo:x86-windows-static zlib:x86-windows-static
|
||||
```
|
||||
|
||||
You can open the folder (as a CMake project). CMake will be detected, and you can compile from there.
|
||||
|
|
|
@ -2,6 +2,3 @@ FROM emscripten/emsdk:3.1.42
|
|||
|
||||
COPY emsdk-liblzma.patch /
|
||||
RUN cd /emsdk/upstream/emscripten && patch -p1 < /emsdk-liblzma.patch
|
||||
|
||||
COPY emsdk-nlohmann-json.patch /
|
||||
RUN cd /emsdk/upstream/emscripten && patch -p1 < /emsdk-nlohmann-json.patch
|
||||
|
|
|
@ -4,7 +4,6 @@ Please use docker with the supplied `Dockerfile` to build for emscripten.
|
|||
It takes care of a few things:
|
||||
- Use a version of emscripten we know works
|
||||
- Patch in LibLZMA support (as this is not supported by upstream)
|
||||
- Patch in nlohmann-json support (as this is not supported by upstream)
|
||||
|
||||
First, build the docker image by navigating in the folder this `README.md` is in, and executing:
|
||||
```
|
||||
|
|
|
@ -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
|
|
@ -3,4 +3,5 @@ add_subdirectory(fmt)
|
|||
add_subdirectory(icu)
|
||||
add_subdirectory(md5)
|
||||
add_subdirectory(squirrel)
|
||||
add_subdirectory(nlohmann)
|
||||
add_subdirectory(opengl)
|
||||
|
|
|
@ -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
|
@ -31,7 +31,7 @@
|
|||
#include "../base_media_base.h"
|
||||
#include "../blitter/factory.hpp"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "../3rdparty/nlohmann/json.hpp"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
|
|
|
@ -10,10 +10,10 @@
|
|||
#include "../../stdafx.h"
|
||||
|
||||
#include "../../3rdparty/fmt/format.h"
|
||||
#include "../../3rdparty/nlohmann/json.hpp"
|
||||
#include "macos.h"
|
||||
|
||||
#include <mach-o/arch.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <thread>
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
|
||||
#include "../../stdafx.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "../../3rdparty/nlohmann/json.hpp"
|
||||
|
||||
#include <sys/utsname.h>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
#include "../../stdafx.h"
|
||||
|
||||
#include "../../3rdparty/fmt/format.h"
|
||||
#include "../../3rdparty/nlohmann/json.hpp"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <thread>
|
||||
#include <windows.h>
|
||||
|
||||
|
|
|
@ -13,8 +13,7 @@
|
|||
#include "../../network/network_admin.h"
|
||||
#include "../script_instance.hpp"
|
||||
#include "../../string_func.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "../../3rdparty/nlohmann/json.hpp"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
|
|
|
@ -18,10 +18,9 @@
|
|||
#include "../../string_func.h"
|
||||
#include "../../economy_cmd.h"
|
||||
#include "../../engine_cmd.h"
|
||||
#include "../../3rdparty/nlohmann/json.hpp"
|
||||
#include "table/strings.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
bool ScriptEventEnginePreview::IsEngineValid() const
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
#include "../script/squirrel.hpp"
|
||||
|
||||
#include "../3rdparty/fmt/format.h"
|
||||
#include "../3rdparty/nlohmann/json.hpp"
|
||||
|
||||
#include <squirrel.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
/**
|
||||
* A controller to start enough so we can use Squirrel for testing.
|
||||
|
|
Loading…
Reference in New Issue