Skip to content

Commit

Permalink
Merge pull request #2686 from rouault/nlohmann_json_update
Browse files Browse the repository at this point in the history
Update internal nlohmann/json to 3.9.1, and add a CMake option to be able to use external nlohmann/json
  • Loading branch information
rouault authored Apr 30, 2021
2 parents 546743c + 29ac85d commit 9d1a7a6
Show file tree
Hide file tree
Showing 11 changed files with 7,327 additions and 4,491 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/clang_linux/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
40 changes: 40 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,49 @@ include(ProjConfig)
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!")
Expand Down
6 changes: 4 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/proj/internal/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBDIRS = nlohmann
SUBDIRS = vendor

noinst_HEADERS = \
coordinatesystem_internal.hpp \
Expand Down
15 changes: 14 additions & 1 deletion include/proj/internal/include_nlohmann_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions include/proj/internal/vendor/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SUBDIRS = nlohmann
File renamed without changes.
Loading

0 comments on commit 9d1a7a6

Please sign in to comment.