aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2021-04-23 14:17:22 +0200
committerEven Rouault <even.rouault@spatialys.com>2021-04-30 13:27:25 +0200
commit29ac85d55273e83a3ada19037959ae7c7823f5b7 (patch)
tree060870053824413937ed2752e5b8f2c791e57530
parent36ac12c74210083ff3d699c9a57bf8b421939483 (diff)
downloadPROJ-29ac85d55273e83a3ada19037959ae7c7823f5b7.tar.gz
PROJ-29ac85d55273e83a3ada19037959ae7c7823f5b7.zip
CMake build: add a NLOHMANN_JSON_ORIGIN=auto/external/internal setting allowing to choose which nlohmann/json to use
Co-authored-by: Mike Taves <mwtoews@gmail.com>
-rwxr-xr-x.github/workflows/clang_linux/start.sh2
-rw-r--r--CMakeLists.txt40
-rw-r--r--configure.ac6
-rw-r--r--include/proj/internal/Makefile.am2
-rw-r--r--include/proj/internal/include_nlohmann_json.hpp15
-rw-r--r--include/proj/internal/vendor/Makefile.am1
-rw-r--r--include/proj/internal/vendor/nlohmann/Makefile.am (renamed from include/proj/internal/nlohmann/Makefile.am)0
-rw-r--r--include/proj/internal/vendor/nlohmann/json.hpp (renamed from include/proj/internal/nlohmann/json.hpp)0
-rw-r--r--src/bin_projsync.cmake5
-rw-r--r--src/lib_proj.cmake6
-rw-r--r--test/unit/CMakeLists.txt8
11 files changed, 79 insertions, 6 deletions
diff --git a/.github/workflows/clang_linux/start.sh b/.github/workflows/clang_linux/start.sh
index a2b6c631..286fdb69 100755
--- a/.github/workflows/clang_linux/start.sh
+++ b/.github/workflows/clang_linux/start.sh
@@ -5,7 +5,7 @@ set -e
apt-get update -y
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
sudo autoconf automake libtool clang++-10 python3-clang-10 make cmake ccache pkg-config tar zip \
- sqlite3 libsqlite3-dev libtiff-dev libcurl4-openssl-dev jq python3-pip
+ sqlite3 libsqlite3-dev libtiff-dev libcurl4-openssl-dev jq python3-pip nlohmann-json3-dev
python3 -m pip install --user jsonschema
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 66c5027f..67a8d2e1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -122,8 +122,48 @@ include(ProjMac)
include(policies)
################################################################################
+# Check for nlohmann_json
+################################################################################
+
+set(NLOHMANN_JSON_ORIGIN "auto" CACHE STRING
+"nlohmann/json origin. The default auto will try to use external \
+nlohmann/json if possible")
+set_property(CACHE NLOHMANN_JSON_ORIGIN PROPERTY STRINGS auto internal external)
+
+# Probably not the strictest minimum, but known to work with it
+set(MIN_NLOHMANN_JSON_VERSION 3.7.0)
+
+if(NLOHMANN_JSON_ORIGIN STREQUAL "external")
+ find_package(nlohmann_json REQUIRED)
+ set(NLOHMANN_JSON "external")
+elseif(NLOHMANN_JSON_ORIGIN STREQUAL "internal")
+ set(NLOHMANN_JSON "internal")
+else()
+ find_package(nlohmann_json QUIET)
+ if(nlohmann_json_FOUND)
+ set(NLOHMANN_JSON "external")
+ else()
+ set(NLOHMANN_JSON "internal")
+ endif()
+endif()
+
+if(NLOHMANN_JSON STREQUAL "external")
+ # Check minimum version
+ if(nlohmann_json_VERSION VERSION_LESS MIN_NLOHMANN_JSON_VERSION)
+ message(STATUS "external nlohmann/json version ${nlohmann_json_VERSION} "
+ "is older than minimum requirement ${MIN_NLOHMANN_JSON_VERSION}")
+ set(NLOHMANN_JSON "internal")
+ else()
+ message(STATUS "found nlohmann/json version ${nlohmann_json_VERSION}")
+ endif()
+endif()
+
+message(STATUS "nlohmann/json: ${NLOHMANN_JSON}")
+
+################################################################################
# Check for sqlite3
################################################################################
+
find_program(EXE_SQLITE3 sqlite3)
if(NOT EXE_SQLITE3)
message(SEND_ERROR "sqlite3 binary not found!")
diff --git a/configure.ac b/configure.ac
index 3e28bbf1..4ff2ad9f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -358,8 +358,10 @@ dnl ---------------------------------------------------------------------------
dnl Generate files
dnl ---------------------------------------------------------------------------
-AC_CONFIG_FILES([Makefile cmake/Makefile src/Makefile include/Makefile include/proj/Makefile include/proj/internal/Makefile
- include/proj/internal/nlohmann/Makefile
+AC_CONFIG_FILES([Makefile cmake/Makefile src/Makefile include/Makefile include/proj/Makefile
+ include/proj/internal/Makefile
+ include/proj/internal/vendor/Makefile
+ include/proj/internal/vendor/nlohmann/Makefile
test/Makefile test/cli/Makefile test/gie/Makefile test/gigs/Makefile test/unit/Makefile
man/Makefile man/man1/Makefile data/Makefile])
if ! test "x$with_external_gtest" = "xyes" ; then
diff --git a/include/proj/internal/Makefile.am b/include/proj/internal/Makefile.am
index 8e9edacf..b3fb57eb 100644
--- a/include/proj/internal/Makefile.am
+++ b/include/proj/internal/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = nlohmann
+SUBDIRS = vendor
noinst_HEADERS = \
coordinatesystem_internal.hpp \
diff --git a/include/proj/internal/include_nlohmann_json.hpp b/include/proj/internal/include_nlohmann_json.hpp
index 68b6836d..6fa5cd2d 100644
--- a/include/proj/internal/include_nlohmann_json.hpp
+++ b/include/proj/internal/include_nlohmann_json.hpp
@@ -26,13 +26,26 @@
* DEALINGS IN THE SOFTWARE.
****************************************************************************/
+#ifndef INCLUDE_NLOHMANN_JSON_HPP
+#define INCLUDE_NLOHMANN_JSON_HPP
+
#if defined(__GNUC__)
#pragma GCC system_header
#endif
+#ifdef EXTERNAL_NLOHMANN_JSON
+
+#include <nlohmann/json.hpp>
+
+#else // !EXTERNAL_NLOHMANN_JSON
+
// to avoid any clash if PROJ users have another version of nlohmann/json.hpp
#define nlohmann proj_nlohmann
#if !defined(DOXYGEN_ENABLED)
-#include "nlohmann/json.hpp"
+#include "vendor/nlohmann/json.hpp"
#endif
+
+#endif // EXTERNAL_NLOHMANN_JSON
+
+#endif // INCLUDE_NLOHMANN_JSON_HPP
diff --git a/include/proj/internal/vendor/Makefile.am b/include/proj/internal/vendor/Makefile.am
new file mode 100644
index 00000000..7d8176b2
--- /dev/null
+++ b/include/proj/internal/vendor/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = nlohmann
diff --git a/include/proj/internal/nlohmann/Makefile.am b/include/proj/internal/vendor/nlohmann/Makefile.am
index eaf3200e..eaf3200e 100644
--- a/include/proj/internal/nlohmann/Makefile.am
+++ b/include/proj/internal/vendor/nlohmann/Makefile.am
diff --git a/include/proj/internal/nlohmann/json.hpp b/include/proj/internal/vendor/nlohmann/json.hpp
index a70aaf8c..a70aaf8c 100644
--- a/include/proj/internal/nlohmann/json.hpp
+++ b/include/proj/internal/vendor/nlohmann/json.hpp
diff --git a/src/bin_projsync.cmake b/src/bin_projsync.cmake
index e18eebd9..ea6bb09c 100644
--- a/src/bin_projsync.cmake
+++ b/src/bin_projsync.cmake
@@ -8,6 +8,11 @@ set_target_properties(bin_projsync
OUTPUT_NAME projsync)
target_link_libraries(bin_projsync PRIVATE ${PROJ_LIBRARIES})
target_compile_options(bin_projsync PRIVATE ${PROJ_CXX_WARN_FLAGS})
+if(NLOHMANN_JSON STREQUAL "external")
+ target_compile_definitions(bin_projsync PRIVATE EXTERNAL_NLOHMANN_JSON)
+ target_link_libraries(bin_projsync PRIVATE nlohmann_json::nlohmann_json)
+endif()
+
install(TARGETS bin_projsync
RUNTIME DESTINATION ${BINDIR})
diff --git a/src/lib_proj.cmake b/src/lib_proj.cmake
index f4adb443..71468c87 100644
--- a/src/lib_proj.cmake
+++ b/src/lib_proj.cmake
@@ -293,7 +293,6 @@ include_directories(${PROJ_SOURCE_DIR}/include)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
source_group("CMake Files" FILES CMakeLists.txt)
-
# Embed PROJ_LIB data files location
add_definitions(-DPROJ_LIB="${CMAKE_INSTALL_PREFIX}/${DATADIR}")
@@ -397,6 +396,11 @@ endif()
target_include_directories(proj PRIVATE ${SQLITE3_INCLUDE_DIR})
target_link_libraries(proj PRIVATE ${SQLITE3_LIBRARY})
+if(NLOHMANN_JSON STREQUAL "external")
+ target_compile_definitions(proj PRIVATE EXTERNAL_NLOHMANN_JSON)
+ target_link_libraries(proj PRIVATE nlohmann_json::nlohmann_json)
+endif()
+
if(TIFF_ENABLED)
target_compile_definitions(proj PRIVATE -DTIFF_ENABLED)
target_include_directories(proj PRIVATE ${TIFF_INCLUDE_DIR})
diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt
index 1a080ac5..53a14ced 100644
--- a/test/unit/CMakeLists.txt
+++ b/test/unit/CMakeLists.txt
@@ -166,6 +166,10 @@ add_executable(test_defmodel
target_link_libraries(test_defmodel
PRIVATE GTest::gtest
PRIVATE ${PROJ_LIBRARIES})
+if(NLOHMANN_JSON STREQUAL "external")
+ target_compile_definitions(test_defmodel PRIVATE EXTERNAL_NLOHMANN_JSON)
+ target_link_libraries(test_defmodel PRIVATE nlohmann_json::nlohmann_json)
+endif()
add_test(NAME test_defmodel COMMAND test_defmodel)
set_property(TEST test_defmodel
PROPERTY ENVIRONMENT ${PROJ_TEST_ENVIRONMENT})
@@ -176,6 +180,10 @@ add_executable(test_tinshift
target_link_libraries(test_tinshift
PRIVATE GTest::gtest
PRIVATE ${PROJ_LIBRARIES})
+if(NLOHMANN_JSON STREQUAL "external")
+ target_compile_definitions(test_tinshift PRIVATE EXTERNAL_NLOHMANN_JSON)
+ target_link_libraries(test_tinshift PRIVATE nlohmann_json::nlohmann_json)
+endif()
add_test(NAME test_tinshift COMMAND test_tinshift)
set_property(TEST test_tinshift
PROPERTY ENVIRONMENT ${PROJ_TEST_ENVIRONMENT})