Skip to content
Snippets Groups Projects
Commit 0b6838b9 authored by Riccardo Maria Bianchi's avatar Riccardo Maria Bianchi :sunny:
Browse files

Fix build when nlohmann_json is not CMake-installed

When nlohmann_json is installed in other ways rather
than by using the CMake setup included within the
package, no CMake config file is installed for
nlohmann_json; and so, it is not possible to use
find_package( nlohmann_json ) in the CMake setup of
our package. This commit fixes the build for the case,
for example, when nohmann_json is installed
by simply copying the single-header file into a system
include folder as '/usr/local/include'.
parent 97f4ac00
Branches
Tags
No related merge requests found
Pipeline #1584533 passed
......@@ -6,7 +6,12 @@ file( GLOB HEADERS GeoModelJSONParser/*.h )
# Create the library.
add_library( GeoModelJSONParser SHARED ${HEADERS} ${SOURCES} )
target_link_libraries( GeoModelJSONParser PUBLIC nlohmann_json::nlohmann_json )
if (nlohmann_json_FOUND)
# we link to nlohmann_json only if we use a version of nlohmann_json installed through CMake;
# this is not needed if the single-header library is installed in a regular
# system include folder (e.g., '/usr/local/include')
target_link_libraries( GeoModelJSONParser PUBLIC nlohmann_json::nlohmann_json )
endif()
target_include_directories( GeoModelJSONParser PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> )
......
......@@ -13,7 +13,7 @@ option( GEOMODEL_USE_BUILTIN_JSON
if( GEOMODEL_USE_BUILTIN_JSON )
# Tell the user what's happening.
message( STATUS "Building nlohmann_json as part of the project" )
message( STATUS "'GEOMODEL_USE_BUILTIN_JSON' was set to 'true' ==> Building nlohmann_json as part of the project" )
# The include directory and library that will be produced.
set( nlohmann_json_INCLUDE_DIR
......@@ -50,6 +50,9 @@ if( GEOMODEL_USE_BUILTIN_JSON )
else()
# Just find an existing installation of nlohmann_json.
find_package( nlohmann_json )
find_package( nlohmann_json QUIET)
if( NOT nlohmann_json_FOUND )
message(STATUS "WARNING! 'nlohmann_json' was not found by CMake!! However, if you installed this single-header library in a standard system include dir (e.g., '/usr/local/include'), I will be able to use it.")
endif()
endif()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment