From c268fb14035678c1a61e7793afe8aaee159094b5 Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Sat, 29 Jun 2024 10:02:46 +0200 Subject: [PATCH] Externalize nlohmann --- CMakeLists.txt | 2 ++ cmake/Findnlohmann_json.cmake | 12 ++++++++++++ external/tinygltf/tiny_gltf.h | 2 +- src/core/CMakeLists.txt | 4 +--- src/core/geometry/qgsabstractgeometry.h | 2 +- src/core/geometry/qgsgeometry.h | 2 +- src/core/qgsgml.h | 2 +- src/core/qgsjsonutils.h | 2 +- src/core/tiledscene/qgscesiumutils.h | 2 +- src/process/CMakeLists.txt | 1 - src/process/qgsprocess.cpp | 2 +- src/providers/mdal/CMakeLists.txt | 1 - src/providers/pdal/qgspdalprovider.cpp | 2 +- src/providers/wfs/CMakeLists.txt | 1 - src/server/qgsserverapiutils.h | 2 +- src/server/qgsserverogcapihandler.h | 2 +- src/server/qgsserverquerystringparameter.h | 2 +- src/server/services/landingpage/CMakeLists.txt | 1 - .../services/landingpage/qgslandingpageutils.h | 2 +- src/server/services/wfs3/CMakeLists.txt | 1 - tests/src/analysis/testqgsprocessing.cpp | 2 +- 21 files changed, 28 insertions(+), 21 deletions(-) create mode 100644 cmake/Findnlohmann_json.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c9c59a31f85..e03058a772d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -367,6 +367,8 @@ if(WITH_CORE) find_package(EXPAT REQUIRED) find_package(Spatialindex REQUIRED) find_package(LibZip REQUIRED) + set (WITH_INTERNAL_NLOHMANN_JSON ON CACHE BOOL "Determines whether the vendored copy of nlohmann-json should be used") + find_package(nlohmann_json REQUIRED) find_package(Sqlite3) if (NOT SQLITE3_FOUND) diff --git a/cmake/Findnlohmann_json.cmake b/cmake/Findnlohmann_json.cmake new file mode 100644 index 000000000000..b5cb02c6f619 --- /dev/null +++ b/cmake/Findnlohmann_json.cmake @@ -0,0 +1,12 @@ +if(WITH_INTERNAL_NLOHMANN_JSON) + # Create imported target nlohmann_json::nlohmann_json + add_library(nlohmann_json::nlohmann_json INTERFACE IMPORTED) + + set_target_properties(nlohmann_json::nlohmann_json PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "\$<\$>:JSON_USE_GLOBAL_UDLS=0>;\$<\$>:JSON_USE_IMPLICIT_CONVERSIONS=0>;\$<\$:JSON_DISABLE_ENUM_SERIALIZATION=1>;\$<\$:JSON_DIAGNOSTICS=1>;\$<\$:JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1>" + INTERFACE_COMPILE_FEATURES "cxx_std_11" + INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/external/nlohmann/" + ) +else() + find_package(nlohmann_json CONFIG REQUIRED) +endif() diff --git a/external/tinygltf/tiny_gltf.h b/external/tinygltf/tiny_gltf.h index bfe045156c71..17fed6e79b48 100644 --- a/external/tinygltf/tiny_gltf.h +++ b/external/tinygltf/tiny_gltf.h @@ -1703,7 +1703,7 @@ class TinyGLTF { #ifndef TINYGLTF_NO_INCLUDE_JSON #ifndef TINYGLTF_USE_RAPIDJSON -#include "json.hpp" +#include #else #ifndef TINYGLTF_NO_INCLUDE_RAPIDJSON #include "document.h" diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 94c0e143001a..afc504cb6d16 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1064,8 +1064,6 @@ else() endif() set(QGIS_CORE_HDRS - ${CMAKE_SOURCE_DIR}/external/nlohmann/json_fwd.hpp - ${CMAKE_BINARY_DIR}/qgsconfig.h ../plugins/qgisplugin.h @@ -2371,7 +2369,6 @@ target_include_directories(qgis_core PUBLIC web ${CMAKE_SOURCE_DIR}/external ${CMAKE_SOURCE_DIR}/external/delaunator-cpp - ${CMAKE_SOURCE_DIR}/external/nlohmann ${CMAKE_SOURCE_DIR}/external/kdbush/include ${CMAKE_SOURCE_DIR}/external/nmea ${CMAKE_SOURCE_DIR}/external/rtree/include @@ -2485,6 +2482,7 @@ target_link_libraries(qgis_core ${ZLIB_LIBRARIES} ${EXIV2_LIBRARY} PROJ::proj + nlohmann_json::nlohmann_json ) if(BUILD_WITH_QT6) diff --git a/src/core/geometry/qgsabstractgeometry.h b/src/core/geometry/qgsabstractgeometry.h index ce380ebf7eb7..0948ff728d12 100644 --- a/src/core/geometry/qgsabstractgeometry.h +++ b/src/core/geometry/qgsabstractgeometry.h @@ -27,7 +27,7 @@ email : marco.hugentobler at sourcepole dot com #include "qgswkbptr.h" #ifndef SIP_RUN -#include "json_fwd.hpp" +#include using namespace nlohmann; #endif diff --git a/src/core/geometry/qgsgeometry.h b/src/core/geometry/qgsgeometry.h index 8e5186b7a40b..d5863c3e08e5 100644 --- a/src/core/geometry/qgsgeometry.h +++ b/src/core/geometry/qgsgeometry.h @@ -38,7 +38,7 @@ email : morb at ozemail dot com dot au #include "qgsvertexid.h" #ifndef SIP_RUN -#include "json_fwd.hpp" +#include using namespace nlohmann; #endif diff --git a/src/core/qgsgml.h b/src/core/qgsgml.h index 9d1ed3458d8f..a4d519b62834 100644 --- a/src/core/qgsgml.h +++ b/src/core/qgsgml.h @@ -33,7 +33,7 @@ #include #ifndef SIP_RUN -#include "json.hpp" +#include #endif class QgsCoordinateReferenceSystem; diff --git a/src/core/qgsjsonutils.h b/src/core/qgsjsonutils.h index a13969a5657a..dbe035a405f7 100644 --- a/src/core/qgsjsonutils.h +++ b/src/core/qgsjsonutils.h @@ -26,7 +26,7 @@ #include #ifndef SIP_RUN -#include "json_fwd.hpp" +#include using namespace nlohmann; #endif diff --git a/src/core/tiledscene/qgscesiumutils.h b/src/core/tiledscene/qgscesiumutils.h index 6dae73c5d479..a022701c25fa 100644 --- a/src/core/tiledscene/qgscesiumutils.h +++ b/src/core/tiledscene/qgscesiumutils.h @@ -23,7 +23,7 @@ #include "qgsbox3d.h" #include "qgsvector3d.h" #include "qgis_sip.h" -#include "nlohmann/json_fwd.hpp" +#include #ifndef SIP_RUN using namespace nlohmann; diff --git a/src/process/CMakeLists.txt b/src/process/CMakeLists.txt index c1947294c69c..ab5a50a093ac 100644 --- a/src/process/CMakeLists.txt +++ b/src/process/CMakeLists.txt @@ -4,7 +4,6 @@ set(QGIS_PROCESS_SRCS main.cpp qgsprocess.cpp - ${CMAKE_SOURCE_DIR}/external/nlohmann/json_fwd.hpp ) if (UNIX AND NOT ANDROID) diff --git a/src/process/qgsprocess.cpp b/src/process/qgsprocess.cpp index bc4ca711d5ff..f0d54d42ccac 100644 --- a/src/process/qgsprocess.cpp +++ b/src/process/qgsprocess.cpp @@ -50,7 +50,7 @@ #include #include #include -#include +#include ConsoleFeedback::ConsoleFeedback( bool useJson ) : mUseJson( useJson ) diff --git a/src/providers/mdal/CMakeLists.txt b/src/providers/mdal/CMakeLists.txt index 10e32fdd5d47..906cb30db609 100644 --- a/src/providers/mdal/CMakeLists.txt +++ b/src/providers/mdal/CMakeLists.txt @@ -72,7 +72,6 @@ if (WITH_INTERNAL_MDAL) ${CMAKE_SOURCE_DIR}/external/mdal/3rdparty/libplyxx.h ${CMAKE_SOURCE_DIR}/external/mdal/3rdparty/libplyxx/libplyxx_internal.h ${CMAKE_SOURCE_DIR}/external/mdal/3rdparty/textio.h - ${CMAKE_SOURCE_DIR}/external/nlohmann/json.hpp ) if(HDF5_FOUND) diff --git a/src/providers/pdal/qgspdalprovider.cpp b/src/providers/pdal/qgspdalprovider.cpp index e87f241ac484..4d5c660f3641 100644 --- a/src/providers/pdal/qgspdalprovider.cpp +++ b/src/providers/pdal/qgspdalprovider.cpp @@ -21,7 +21,7 @@ #include "qgsapplication.h" #include "qgslogger.h" #include "qgsjsonutils.h" -#include "json.hpp" +#include #include "qgspdalindexingtask.h" #include "qgseptpointcloudindex.h" #include "qgstaskmanager.h" diff --git a/src/providers/wfs/CMakeLists.txt b/src/providers/wfs/CMakeLists.txt index 37b8cb1a2060..638794a15c76 100644 --- a/src/providers/wfs/CMakeLists.txt +++ b/src/providers/wfs/CMakeLists.txt @@ -3,7 +3,6 @@ # Files set(WFS_SRCS - ${CMAKE_SOURCE_DIR}/external/nlohmann/json.hpp qgswfsprovider.cpp qgswfsprovidermetadata.cpp qgswfscapabilities.cpp diff --git a/src/server/qgsserverapiutils.h b/src/server/qgsserverapiutils.h index eec7295b4f79..676c87fd6e25 100644 --- a/src/server/qgsserverapiutils.h +++ b/src/server/qgsserverapiutils.h @@ -41,7 +41,7 @@ class QgsCoordinateReferenceSystem; class QgsVectorLayer; #ifndef SIP_RUN -#include "nlohmann/json_fwd.hpp" +#include using namespace nlohmann; #endif diff --git a/src/server/qgsserverogcapihandler.h b/src/server/qgsserverogcapihandler.h index c864f30486f2..6ecc1275cce0 100644 --- a/src/server/qgsserverogcapihandler.h +++ b/src/server/qgsserverogcapihandler.h @@ -20,7 +20,7 @@ #include "qgis_server.h" #include "qgsserverquerystringparameter.h" #include "qgsserverogcapi.h" -#include "nlohmann/json_fwd.hpp" +#include #include "inja/inja.hpp" #ifndef SIP_RUN diff --git a/src/server/qgsserverquerystringparameter.h b/src/server/qgsserverquerystringparameter.h index 50dece21573c..2ec40e206391 100644 --- a/src/server/qgsserverquerystringparameter.h +++ b/src/server/qgsserverquerystringparameter.h @@ -24,7 +24,7 @@ #include -#include "nlohmann/json_fwd.hpp" +#include #ifndef SIP_RUN using namespace nlohmann; diff --git a/src/server/services/landingpage/CMakeLists.txt b/src/server/services/landingpage/CMakeLists.txt index 713091e86856..5d59961b9e21 100644 --- a/src/server/services/landingpage/CMakeLists.txt +++ b/src/server/services/landingpage/CMakeLists.txt @@ -2,7 +2,6 @@ # Files set (LANDINGPAGE_SRCS - ${CMAKE_SOURCE_DIR}/external/nlohmann/json.hpp ${CMAKE_SOURCE_DIR}/external/inja/inja.hpp qgslandingpage.cpp qgslandingpageutils.cpp diff --git a/src/server/services/landingpage/qgslandingpageutils.h b/src/server/services/landingpage/qgslandingpageutils.h index 81d31569ffe0..6b4bc217031b 100644 --- a/src/server/services/landingpage/qgslandingpageutils.h +++ b/src/server/services/landingpage/qgslandingpageutils.h @@ -20,7 +20,7 @@ #include #include -#include "nlohmann/json_fwd.hpp" +#include #include "qgsserversettings.h" #include "qgsserverrequest.h" diff --git a/src/server/services/wfs3/CMakeLists.txt b/src/server/services/wfs3/CMakeLists.txt index d1858fcd5b62..b0b8a2440989 100644 --- a/src/server/services/wfs3/CMakeLists.txt +++ b/src/server/services/wfs3/CMakeLists.txt @@ -2,7 +2,6 @@ # Files set (WFS3_SRCS - ${CMAKE_SOURCE_DIR}/external/nlohmann/json.hpp ${CMAKE_SOURCE_DIR}/external/inja/inja.hpp qgswfs3.cpp qgswfs3handlers.cpp diff --git a/tests/src/analysis/testqgsprocessing.cpp b/tests/src/analysis/testqgsprocessing.cpp index 14b8ae41531b..1cc38a6b06ec 100644 --- a/tests/src/analysis/testqgsprocessing.cpp +++ b/tests/src/analysis/testqgsprocessing.cpp @@ -56,7 +56,7 @@ #include "qgspointcloudlayer.h" #include "qgsannotationlayer.h" #include "qgsjsonutils.h" -#include "json.hpp" +#include #include "qgsspatialindex.h" #include "qgstiledscenelayer.h" #include "qgsalignrasterdata.h"