From a3d631ffed4d86309ec132a7e6a5b38a100df7d4 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Mon, 28 Aug 2023 19:04:36 +0200 Subject: [PATCH] Change: make nlohmann a mandatory library to build OpenTTD (#11235) --- .github/workflows/ci-build.yml | 9 +++++---- CMakeLists.txt | 5 +++-- COMPILING.md | 2 +- src/network/network_survey.cpp | 10 ---------- src/network/network_survey.h | 5 ----- src/os/macosx/survey_osx.cpp | 4 ---- src/os/unix/survey_unix.cpp | 4 ---- src/os/windows/survey_win.cpp | 4 ---- 8 files changed, 9 insertions(+), 34 deletions(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index f7cd10c17e..3faeafe6c3 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -77,20 +77,20 @@ jobs: - name: Clang compiler: clang cxxcompiler: clang++ - libraries: libsdl2-dev nlohmann-json3-dev + libraries: libsdl2-dev - name: GCC - SDL2 compiler: gcc cxxcompiler: g++ - libraries: libsdl2-dev nlohmann-json3-dev + libraries: libsdl2-dev - name: GCC - SDL1.2 compiler: gcc cxxcompiler: g++ - libraries: libsdl1.2-dev nlohmann-json3-dev + libraries: libsdl1.2-dev - name: GCC - Dedicated compiler: gcc cxxcompiler: g++ extra-cmake-parameters: -DOPTION_DEDICATED=ON -DCMAKE_CXX_FLAGS_INIT="-DRANDOM_DEBUG" -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON - # Compile without SDL / SDL2 / nlohmann-json, as that should compile fine too. + # Compile without SDL / SDL2, as that should compile fine too. name: Linux (${{ matrix.name }}) @@ -118,6 +118,7 @@ jobs: libicu-dev \ liblzma-dev \ liblzo2-dev \ + nlohmann-json3-dev \ ${{ matrix.libraries }} \ zlib1g-dev \ # EOF diff --git a/CMakeLists.txt b/CMakeLists.txt index e699c4d56d..400c145e08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,12 +119,13 @@ 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) find_package(LZO) find_package(PNG) -find_package(nlohmann_json) if(WIN32 OR EMSCRIPTEN) # Windows uses WinHttp for HTTP requests. @@ -309,7 +310,7 @@ 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 ENCOURAGED) +link_package(nlohmann_json) if(NOT WIN32 AND NOT EMSCRIPTEN) link_package(CURL ENCOURAGED) diff --git a/COMPILING.md b/COMPILING.md index ef9589366d..5e7883aefc 100644 --- a/COMPILING.md +++ b/COMPILING.md @@ -4,7 +4,7 @@ OpenTTD makes use of the following external libraries: -- (encouraged) nlohmann-json: JSON handling +- (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 diff --git a/src/network/network_survey.cpp b/src/network/network_survey.cpp index 55cb7b5972..afe52d6999 100644 --- a/src/network/network_survey.cpp +++ b/src/network/network_survey.cpp @@ -31,9 +31,7 @@ #include "../base_media_base.h" #include "../blitter/factory.hpp" -#ifdef WITH_NLOHMANN_JSON #include -#endif /* WITH_NLOHMANN_JSON */ #include "../safeguards.h" @@ -41,8 +39,6 @@ extern std::string _savegame_id; NetworkSurveyHandler _survey = {}; -#ifdef WITH_NLOHMANN_JSON - NLOHMANN_JSON_SERIALIZE_ENUM(NetworkSurveyHandler::Reason, { {NetworkSurveyHandler::Reason::PREVIEW, "preview"}, {NetworkSurveyHandler::Reason::LEAVE, "leave"}, @@ -334,8 +330,6 @@ std::string SurveyMemoryToText(uint64_t memory) return fmt::format("{} MiB", Ceil(memory, 4)); } -#endif /* WITH_NLOHMANN_JSON */ - /** * Create the payload for the survey. * @@ -345,9 +339,6 @@ std::string SurveyMemoryToText(uint64_t memory) */ std::string NetworkSurveyHandler::CreatePayload(Reason reason, bool for_preview) { -#ifndef WITH_NLOHMANN_JSON - return ""; -#else nlohmann::json survey; survey["schema"] = NETWORK_SURVEY_VERSION; @@ -381,7 +372,6 @@ std::string NetworkSurveyHandler::CreatePayload(Reason reason, bool for_preview) /* For preview, we indent with 4 whitespaces to make things more readable. */ int indent = for_preview ? 4 : -1; return survey.dump(indent); -#endif /* WITH_NLOHMANN_JSON */ } /** diff --git a/src/network/network_survey.h b/src/network/network_survey.h index c957108ecf..fbad97bfab 100644 --- a/src/network/network_survey.h +++ b/src/network/network_survey.h @@ -36,12 +36,7 @@ public: constexpr static bool IsSurveyPossible() { -#ifndef WITH_NLOHMANN_JSON - /* Without JSON library, we cannot send a payload; so we disable the survey. */ - return false; -#else return true; -#endif /* WITH_NLOHMANN_JSON */ } private: diff --git a/src/os/macosx/survey_osx.cpp b/src/os/macosx/survey_osx.cpp index 14260fbd68..c8483b20ff 100644 --- a/src/os/macosx/survey_osx.cpp +++ b/src/os/macosx/survey_osx.cpp @@ -7,8 +7,6 @@ /** @file survey_osx.cpp OSX implementation of OS-specific survey information. */ -#ifdef WITH_NLOHMANN_JSON - #include "../../stdafx.h" #include "../../3rdparty/fmt/format.h" @@ -38,5 +36,3 @@ void SurveyOS(nlohmann::json &json) json["memory"] = SurveyMemoryToText(MacOSGetPhysicalMemory()); json["hardware_concurrency"] = std::thread::hardware_concurrency(); } - -#endif /* WITH_NLOHMANN_JSON */ diff --git a/src/os/unix/survey_unix.cpp b/src/os/unix/survey_unix.cpp index d831a78390..fea37d89da 100644 --- a/src/os/unix/survey_unix.cpp +++ b/src/os/unix/survey_unix.cpp @@ -7,8 +7,6 @@ /** @file survey_unix.cpp Unix implementation of OS-specific survey information. */ -#ifdef WITH_NLOHMANN_JSON - #include "../../stdafx.h" #include @@ -38,5 +36,3 @@ void SurveyOS(nlohmann::json &json) json["memory"] = SurveyMemoryToText(pages * page_size); json["hardware_concurrency"] = std::thread::hardware_concurrency(); } - -#endif /* WITH_NLOHMANN_JSON */ diff --git a/src/os/windows/survey_win.cpp b/src/os/windows/survey_win.cpp index 1af48a39e7..9044f8c22f 100644 --- a/src/os/windows/survey_win.cpp +++ b/src/os/windows/survey_win.cpp @@ -7,8 +7,6 @@ /** @file survey_win.cpp Windows implementation of OS-specific survey information. */ -#ifdef WITH_NLOHMANN_JSON - #include "../../stdafx.h" #include "../../3rdparty/fmt/format.h" @@ -37,5 +35,3 @@ void SurveyOS(nlohmann::json &json) json["memory"] = SurveyMemoryToText(status.ullTotalPhys); json["hardware_concurrency"] = std::thread::hardware_concurrency(); } - -#endif /* WITH_NLOHMANN_JSON */