Change: make nlohmann a mandatory library to build OpenTTD (#11235)

This commit is contained in:
Patric Stout 2023-08-28 19:04:36 +02:00 committed by GitHub
parent 13b76b0243
commit a3d631ffed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 9 additions and 34 deletions

View File

@ -77,20 +77,20 @@ jobs:
- name: Clang - name: Clang
compiler: clang compiler: clang
cxxcompiler: clang++ cxxcompiler: clang++
libraries: libsdl2-dev nlohmann-json3-dev libraries: libsdl2-dev
- name: GCC - SDL2 - name: GCC - SDL2
compiler: gcc compiler: gcc
cxxcompiler: g++ cxxcompiler: g++
libraries: libsdl2-dev nlohmann-json3-dev libraries: libsdl2-dev
- name: GCC - SDL1.2 - name: GCC - SDL1.2
compiler: gcc compiler: gcc
cxxcompiler: g++ cxxcompiler: g++
libraries: libsdl1.2-dev nlohmann-json3-dev libraries: libsdl1.2-dev
- name: GCC - Dedicated - name: GCC - Dedicated
compiler: gcc compiler: gcc
cxxcompiler: g++ cxxcompiler: g++
extra-cmake-parameters: -DOPTION_DEDICATED=ON -DCMAKE_CXX_FLAGS_INIT="-DRANDOM_DEBUG" -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON 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 }}) name: Linux (${{ matrix.name }})
@ -118,6 +118,7 @@ jobs:
libicu-dev \ libicu-dev \
liblzma-dev \ liblzma-dev \
liblzo2-dev \ liblzo2-dev \
nlohmann-json3-dev \
${{ matrix.libraries }} \ ${{ matrix.libraries }} \
zlib1g-dev \ zlib1g-dev \
# EOF # EOF

View File

@ -119,12 +119,13 @@ endif()
set(CMAKE_THREAD_PREFER_PTHREAD YES) set(CMAKE_THREAD_PREFER_PTHREAD YES)
# Make sure we have Threads available. # Make sure we have Threads available.
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
# nlohmann is used for all our JSON needs.
find_package(nlohmann_json REQUIRED)
find_package(ZLIB) find_package(ZLIB)
find_package(LibLZMA) find_package(LibLZMA)
find_package(LZO) find_package(LZO)
find_package(PNG) find_package(PNG)
find_package(nlohmann_json)
if(WIN32 OR EMSCRIPTEN) if(WIN32 OR EMSCRIPTEN)
# Windows uses WinHttp for HTTP requests. # 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(ZLIB TARGET ZLIB::ZLIB ENCOURAGED)
link_package(LIBLZMA TARGET LibLZMA::LibLZMA ENCOURAGED) link_package(LIBLZMA TARGET LibLZMA::LibLZMA ENCOURAGED)
link_package(LZO) link_package(LZO)
link_package(nlohmann_json ENCOURAGED) link_package(nlohmann_json)
if(NOT WIN32 AND NOT EMSCRIPTEN) if(NOT WIN32 AND NOT EMSCRIPTEN)
link_package(CURL ENCOURAGED) link_package(CURL ENCOURAGED)

View File

@ -4,7 +4,7 @@
OpenTTD makes use of the following external libraries: 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) breakpad: creates minidumps on crash
- (encouraged) zlib: (de)compressing of old (0.3.0-1.0.5) savegames, content downloads, - (encouraged) zlib: (de)compressing of old (0.3.0-1.0.5) savegames, content downloads,
heightmaps heightmaps

View File

@ -31,9 +31,7 @@
#include "../base_media_base.h" #include "../base_media_base.h"
#include "../blitter/factory.hpp" #include "../blitter/factory.hpp"
#ifdef WITH_NLOHMANN_JSON
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#endif /* WITH_NLOHMANN_JSON */
#include "../safeguards.h" #include "../safeguards.h"
@ -41,8 +39,6 @@ extern std::string _savegame_id;
NetworkSurveyHandler _survey = {}; NetworkSurveyHandler _survey = {};
#ifdef WITH_NLOHMANN_JSON
NLOHMANN_JSON_SERIALIZE_ENUM(NetworkSurveyHandler::Reason, { NLOHMANN_JSON_SERIALIZE_ENUM(NetworkSurveyHandler::Reason, {
{NetworkSurveyHandler::Reason::PREVIEW, "preview"}, {NetworkSurveyHandler::Reason::PREVIEW, "preview"},
{NetworkSurveyHandler::Reason::LEAVE, "leave"}, {NetworkSurveyHandler::Reason::LEAVE, "leave"},
@ -334,8 +330,6 @@ std::string SurveyMemoryToText(uint64_t memory)
return fmt::format("{} MiB", Ceil(memory, 4)); return fmt::format("{} MiB", Ceil(memory, 4));
} }
#endif /* WITH_NLOHMANN_JSON */
/** /**
* Create the payload for the survey. * 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) std::string NetworkSurveyHandler::CreatePayload(Reason reason, bool for_preview)
{ {
#ifndef WITH_NLOHMANN_JSON
return "";
#else
nlohmann::json survey; nlohmann::json survey;
survey["schema"] = NETWORK_SURVEY_VERSION; 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. */ /* For preview, we indent with 4 whitespaces to make things more readable. */
int indent = for_preview ? 4 : -1; int indent = for_preview ? 4 : -1;
return survey.dump(indent); return survey.dump(indent);
#endif /* WITH_NLOHMANN_JSON */
} }
/** /**

View File

@ -36,12 +36,7 @@ public:
constexpr static bool IsSurveyPossible() 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; return true;
#endif /* WITH_NLOHMANN_JSON */
} }
private: private:

View File

@ -7,8 +7,6 @@
/** @file survey_osx.cpp OSX implementation of OS-specific survey information. */ /** @file survey_osx.cpp OSX implementation of OS-specific survey information. */
#ifdef WITH_NLOHMANN_JSON
#include "../../stdafx.h" #include "../../stdafx.h"
#include "../../3rdparty/fmt/format.h" #include "../../3rdparty/fmt/format.h"
@ -38,5 +36,3 @@ void SurveyOS(nlohmann::json &json)
json["memory"] = SurveyMemoryToText(MacOSGetPhysicalMemory()); json["memory"] = SurveyMemoryToText(MacOSGetPhysicalMemory());
json["hardware_concurrency"] = std::thread::hardware_concurrency(); json["hardware_concurrency"] = std::thread::hardware_concurrency();
} }
#endif /* WITH_NLOHMANN_JSON */

View File

@ -7,8 +7,6 @@
/** @file survey_unix.cpp Unix implementation of OS-specific survey information. */ /** @file survey_unix.cpp Unix implementation of OS-specific survey information. */
#ifdef WITH_NLOHMANN_JSON
#include "../../stdafx.h" #include "../../stdafx.h"
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
@ -38,5 +36,3 @@ void SurveyOS(nlohmann::json &json)
json["memory"] = SurveyMemoryToText(pages * page_size); json["memory"] = SurveyMemoryToText(pages * page_size);
json["hardware_concurrency"] = std::thread::hardware_concurrency(); json["hardware_concurrency"] = std::thread::hardware_concurrency();
} }
#endif /* WITH_NLOHMANN_JSON */

View File

@ -7,8 +7,6 @@
/** @file survey_win.cpp Windows implementation of OS-specific survey information. */ /** @file survey_win.cpp Windows implementation of OS-specific survey information. */
#ifdef WITH_NLOHMANN_JSON
#include "../../stdafx.h" #include "../../stdafx.h"
#include "../../3rdparty/fmt/format.h" #include "../../3rdparty/fmt/format.h"
@ -37,5 +35,3 @@ void SurveyOS(nlohmann::json &json)
json["memory"] = SurveyMemoryToText(status.ullTotalPhys); json["memory"] = SurveyMemoryToText(status.ullTotalPhys);
json["hardware_concurrency"] = std::thread::hardware_concurrency(); json["hardware_concurrency"] = std::thread::hardware_concurrency();
} }
#endif /* WITH_NLOHMANN_JSON */