From 8bff78588634d41769255a777c21f41173810668 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Fri, 20 Nov 2026 16:34:04 +0100 Subject: [PATCH] build: optionally use the system nlohmann_json (USE_SYSTEM_JSON) (#360) USE_SYSTEM_JSON (default OFF) takes an installed nlohmann_json 3.9 or newer (ordered_json, used by the unit tests) with find_package instead of the ref/json submodule. Both give the nlohmann_json::nlohmann_json target linked to eu07_settings. Drop the include directory from the never defined NLOHMANN_JSON_INCLUDE_INSTALL_DIR. Fixes #54. --- CMakeLists.txt | 11 ++++++++--- README.md | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e80acbf7..cf1b137f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,6 +86,7 @@ option(ENABLE_MCC "Enable multicore compilation" ON) option(WITHDUMPGEN "Enable generating DMP files on crash" ON) option(ENABLE_AVX2 "Enable AVX2 instruction set (requires AVX2-capable CPU, Haswell/2013 or newer)" ON) option(ADD_VERSION_SUFFIX "Add date and commit hash to the executable name" ON) +option(USE_SYSTEM_JSON "Use an installed nlohmann_json (3.9 or newer) instead of the ref/json submodule" OFF) set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # vcpkg init @@ -698,10 +699,14 @@ target_link_libraries(eu07_settings INTERFACE Threads::Threads) find_package(GLM REQUIRED) target_include_directories(eu07_settings INTERFACE ${GLM_INCLUDE_DIR}) -# JSON lib -add_subdirectory(ref/json) +# JSON lib: the ref/json submodule by default, or an installed package (e.g. nlohmann-json3-dev, vcpkg nlohmann-json). +# Both give the nlohmann_json::nlohmann_json target; 3.9 is the first release with ordered_json, used by the unit tests. +if (USE_SYSTEM_JSON) + find_package(nlohmann_json 3.9 REQUIRED) +else() + add_subdirectory(ref/json) +endif() target_link_libraries(eu07_settings INTERFACE nlohmann_json::nlohmann_json) -target_include_directories(eu07_settings INTERFACE ${NLOHMANN_JSON_INCLUDE_INSTALL_DIR}) diff --git a/README.md b/README.md index 675026ccf..f0c7ac3cd 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ MaSzyna compiles and runs natively on **Linux** and **Windows**. Other platforms | `-DCMAKE_BUILD_TYPE=Release` | Release build | | `-DCMAKE_BUILD_TYPE=RelWithDebInfo` | Release build with debug symbols | | `-DWITH_BETTER_RENDERER=ON/OFF` | Enable/disable NVRHI-based renderer | +| `-DUSE_SYSTEM_JSON=ON/OFF` | Use an installed **nlohmann_json** 3.9 or newer (e.g. `nlohmann-json3-dev`, vcpkg `nlohmann-json`) instead of the `ref/json` submodule (default `OFF`) | | `-DPython3_ROOT_DIR=` | Root of the **Python 3.14** install on Windows (`python.exe`, `Lib`, `DLLs`) for embed/copy steps; on Linux, optional if CMake picks the wrong interpreter | > **Linux note:** `WITH_BETTER_RENDERER` uses DirectX 12 through NVRHI and is **not supported on Linux**.