Skip to content

Commit

Permalink
Merge pull request #7 from mwtoews/nlohmann_json_update
Browse files Browse the repository at this point in the history
Several suggestions
  • Loading branch information
rouault authored Apr 30, 2021
2 parents 9f2e13c + cdb8c95 commit b495917
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 136 deletions.
29 changes: 20 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,28 +125,39 @@ 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(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 EQUAL "external")
find_package(nlohmann_json ${MIN_NLOHMANN_JSON_VERSION} REQUIRED)
set(NLOHMANN_JSON "external")

elseif(NLOHMANN_JSON_ORIGIN EQUAL "internal")
set(NLOHMANN_JSON "internal")

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 ${MIN_NLOHMANN_JSON_VERSION})
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}")

################################################################################
Expand Down
77 changes: 0 additions & 77 deletions cmake/Findnlohmann_json.cmake

This file was deleted.

4 changes: 1 addition & 3 deletions cmake/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ EXTRA_DIST = CMakeLists.txt \
proj_config.cmake.in \
project-config-version.cmake.in \
project-config.cmake.in \
FindSqlite3.cmake \
Findnlohmann_json.cmake \
ParseVersion.cmake
FindSqlite3.cmake

37 changes: 0 additions & 37 deletions cmake/ParseVersion.cmake

This file was deleted.

5 changes: 5 additions & 0 deletions src/bin_projsync.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
10 changes: 5 additions & 5 deletions src/lib_proj.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,6 @@ include_directories(${PROJ_SOURCE_DIR}/include)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
source_group("CMake Files" FILES CMakeLists.txt)

if("${NLOHMANN_JSON}" EQUAL "external")
add_definitions(-DEXTERNAL_NLOHMANN_JSON)
include_directories(${NLOHMANN_JSON_INCLUDE_DIRS})
endif()

# Embed PROJ_LIB data files location
add_definitions(-DPROJ_LIB="${CMAKE_INSTALL_PREFIX}/${DATADIR}")

Expand Down Expand Up @@ -401,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})
Expand Down
13 changes: 8 additions & 5 deletions test/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ include_directories(${SQLITE3_INCLUDE_DIR})
# Add the directory containing proj_config.h
include_directories(${PROJ_BINARY_DIR}/src)

if("${NLOHMANN_JSON}" EQUAL "external")
add_definitions(-DEXTERNAL_NLOHMANN_JSON)
include_directories(${NLOHMANN_JSON_INCLUDE_DIRS})
endif()

# Apply to targets in the current directory and below
add_compile_options(${PROJ_CXX_WARN_FLAGS})

Expand Down Expand Up @@ -171,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})
Expand All @@ -181,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})
Expand Down

0 comments on commit b495917

Please sign in to comment.