Skip to content
Snippets Groups Projects
Commit 195e14ca authored by Attila Krasznahorkay's avatar Attila Krasznahorkay
Browse files

Taught the project how to build nlohmann_json on its own if necessary.

parent 2c567db3
Branches
Tags
1 merge request!1CMake Build Configuration Updates, master branch (2020.03.12.)
...@@ -17,11 +17,11 @@ include( GNUInstallDirs ) ...@@ -17,11 +17,11 @@ include( GNUInstallDirs )
# Set up the "optional" dependencies. # Set up the "optional" dependencies.
include( SetupXercesC ) include( SetupXercesC )
include( SetupJSON )
# Find the externals needed by the project. # Find the externals needed by the project.
find_package( GeoModelCore REQUIRED ) find_package( GeoModelCore REQUIRED )
find_package( GeoModelIO REQUIRED ) find_package( GeoModelIO REQUIRED )
find_package( nlohmann_json )
# Set up the build of the libraries of the project. # Set up the build of the libraries of the project.
add_subdirectory( XMLParser ) add_subdirectory( XMLParser )
......
...@@ -6,11 +6,7 @@ file( GLOB HEADERS JSONParser/*.h ) ...@@ -6,11 +6,7 @@ file( GLOB HEADERS JSONParser/*.h )
# Create the library. # Create the library.
add_library( JSONParser SHARED ${HEADERS} ${SOURCES} ) add_library( JSONParser SHARED ${HEADERS} ${SOURCES} )
if( nlohmann_json_FOUND ) target_link_libraries( JSONParser PUBLIC nlohmann_json::nlohmann_json )
target_link_libraries( JSONParser PUBLIC nlohmann_json::nlohmann_json )
else()
message( WARNING "'nlohmann_json' not found by CMake! The build may fail." )
endif()
target_include_directories( JSONParser PUBLIC target_include_directories( JSONParser PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> )
...@@ -19,6 +15,9 @@ source_group( "src" FILES ${SOURCES} ) ...@@ -19,6 +15,9 @@ source_group( "src" FILES ${SOURCES} )
set_target_properties( JSONParser PROPERTIES set_target_properties( JSONParser PROPERTIES
VERSION ${PROJECT_VERSION} VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR} ) SOVERSION ${PROJECT_VERSION_MAJOR} )
if( GEOMODEL_USE_BUILTIN_JSON )
add_dependencies( JSONParser JSON )
endif()
# Install the library. # Install the library.
install( TARGETS JSONParser install( TARGETS JSONParser
......
# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
#
# This module is used to set up nlohmann_json for the project. Either by
# looking for it on the build machine, or by downloading it during the build
# itself.
#
# Configuration option for how XercesC should be used.
option( GEOMODEL_USE_BUILTIN_JSON
"Download a version of nlohmann_json during the build" FALSE )
# Now do what was requested.
if( GEOMODEL_USE_BUILTIN_JSON )
# Tell the user what's happening.
message( STATUS "Building nlohmann_json as part of the project" )
# The include directory and library that will be produced.
set( nlohmann_json_INCLUDE_DIR
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/JSONInstall/${CMAKE_INSTALL_INCLUDEDIR}" )
set( nlohmann_json_INCLUDE_DIRS "${nlohmann_json_INCLUDE_DIR}" )
# Create the include directory already, otherwise CMake refuses to
# create the imported target.
file( MAKE_DIRECTORY "${nlohmann_json_INCLUDE_DIR}" )
# Build/install nlohmann_json using ExternalProject_Add(...).
include( ExternalProject )
ExternalProject_Add( JSON
PREFIX ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/JSONBuild
INSTALL_DIR ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/JSONInstall
URL "https://cern.ch/lcgpackages/tarFiles/sources/json-3.6.1.tar.gz"
URL_MD5 "c53592d55e7fec787cf0a406d36098a3"
CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD}
-DJSON_BuildTests:BOOL=OFF -DJSON_MultipleHeaders:BOOL=ON
BUILD_BYPRODUCTS "${nlohmann_json_INCLUDE_DIR}" )
install( DIRECTORY
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/JSONInstall/
DESTINATION .
COMPONENT Development
USE_SOURCE_PERMISSIONS )
# Set up nlohmann_json's imported target.
add_library( nlohmann_json::nlohmann_json INTERFACE IMPORTED )
set_target_properties( nlohmann_json::nlohmann_json PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${nlohmann_json_INCLUDE_DIR}" )
else()
# Just find an existing installation of nlohmann_json.
find_package( nlohmann_json )
endif()
...@@ -22,6 +22,8 @@ if( GEOMODEL_USE_BUILTIN_XERCESC ) ...@@ -22,6 +22,8 @@ if( GEOMODEL_USE_BUILTIN_XERCESC )
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCInstall/${CMAKE_INSTALL_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}xerces-c${CMAKE_SHARED_LIBRARY_SUFFIX}" ) "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCInstall/${CMAKE_INSTALL_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}xerces-c${CMAKE_SHARED_LIBRARY_SUFFIX}" )
set( XercesC_LIBRARIES "${XercesC_LIBRARY}" ) set( XercesC_LIBRARIES "${XercesC_LIBRARY}" )
# Create the include directory already, otherwise CMake refuses to
# create the imported target.
file( MAKE_DIRECTORY "${XercesC_INCLUDE_DIR}" ) file( MAKE_DIRECTORY "${XercesC_INCLUDE_DIR}" )
# Build/install Eigen3 using ExternalProject_Add(...). # Build/install Eigen3 using ExternalProject_Add(...).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment