Skip to content
Snippets Groups Projects
Commit fe713b5e 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 23fbb980
Branches
Tags
No related merge requests found
# List of the CI build stages.
stages:
- deps-A
- deps-B
- build
# List global variables
variables:
CMAKE_BASE_ARGS: -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../install
CMAKE_BASE_ARGS: -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../dependencies-install -DCMAKE_PREFIX_PATH=${PWD}/../dependencies-install
GIT_SUBMODULE_STRATEGY: recursive
......@@ -16,19 +17,27 @@ variables:
allow_failure: true
timeout: 30 minutes
before_script:
- brew install nlohmann-json
- export PATH="/usr/local/opt/qt/bin:$PATH" # to make Qt5 discoverable by CMake
.ubuntu-template-job: &ubuntu-job
.ubuntu-template-job-base: &ubuntu-job-base
image: ubuntu:18.04
tags:
- docker
# NOTE
# The Ubuntu package 'nlohmann-json-dev' is version 2.x, too old for us.
# Thus, for GeoModelVisualization (GMEX), we now build nlohmann_json as part
# of the build, by using the 'standalone' job only
.ubuntu-template-job-default: &ubuntu-job
<<: *ubuntu-job-base
before_script:
- apt-get update -qq && apt-get install -y -qq git cmake wget unzip build-essential freeglut3-dev libboost-all-dev qt5-default mercurial libeigen3-dev
# TEMPLATES FOR PACKAGES
.coin-build-template-job: &coin-job
.coin-build-template: &coin-job
stage: deps-A
variables:
CMAKE_ARGS: ${CMAKE_BASE_ARGS}
......@@ -44,9 +53,9 @@ variables:
- make install
artifacts:
paths:
- install
- dependencies-install/
.soqt-build-template-job: &soqt-job
.soqt-build-template: &soqt-job
stage: deps-B
variables:
CMAKE_ARGS: ${CMAKE_BASE_ARGS}
......@@ -65,9 +74,9 @@ variables:
- make install
artifacts:
paths:
- install
- dependencies-install/
.geomodelcore-build-template-job: &geomodelcore-job
.geomodelcore-build-template: &geomodelcore-job
stage: deps-A
variables:
CMAKE_ARGS: ${CMAKE_BASE_ARGS}
......@@ -81,9 +90,9 @@ variables:
- make install
artifacts:
paths:
- install
- dependencies-install/
.geomodelio-build-template-job: &geomodelio-job
.geomodelio-build-template: &geomodelio-job
stage: deps-B
variables:
CMAKE_ARGS: ${CMAKE_BASE_ARGS}
......@@ -97,77 +106,102 @@ variables:
- make install
artifacts:
paths:
- install
- dependencies-install/
.geomodelvisualization-build-template: &geomodelvisualization-job
stage: build
variables:
CMAKE_ARGS: ${CMAKE_BASE_ARGS} ${CMAKE_EXTRA_FLAGS}
script:
- echo "PWD; LS"
- pwd; ls
- mkdir build
- cd build
- cmake ${CMAKE_ARGS} ..
- cmake --build . -- -j2
- cmake ${CMAKE_ARGS} ${CMAKE_EXTRA_FLAGS} ..
- cmake --build . -- -j
- cmake --build . -- install
artifacts:
paths:
- dependencies-install/
.geomodelvisualization-build-template-mac: &geomodelvisualization-job-mac
stage: build
script:
- echo "PWD; LS"
- pwd; ls
- mkdir build
# - pwd; ls # for debug
# - ls dependencies-install/ # for debug
# - ls ../../; # for debug
# - ls ../../../; # for debug
# - ls ../../../../ # for debug
- cd build
- cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../install -DCMAKE_PREFIX_PATH=${PWD}/../dependencies-install ../
- cmake --build . -- -j
- cmake --build . -- install
artifacts:
paths:
- install
# ACTUAL JOBS
### MACOS PATH
coin-mac:
mac-coin:
<<: *macos-job
<<: *coin-job
soqt-mac:
mac-soqt:
<<: *macos-job
<<: *soqt-job
needs: ["coin-mac"]
needs: ["mac-coin"]
geomodelcore-mac:
mac-geomodelcore:
<<: *macos-job
<<: *geomodelcore-job
geomodelio-mac:
mac-geomodelio:
<<: *macos-job
<<: *geomodelio-job
needs: ["geomodelcore-mac"]
needs: ["mac-geomodelcore"]
geomodelvisualization-mac:
mac-gmex:
<<: *macos-job
<<: *geomodelvisualization-job
needs: ["coin-mac", "soqt-mac", "geomodelcore-mac", "geomodelio-mac"]
<<: *geomodelvisualization-job-mac
needs: ["mac-coin", "mac-soqt", "mac-geomodelcore", "mac-geomodelio"]
### UBUNTU PATH
coin-ubuntu:
ubuntu-coin:
<<: *ubuntu-job
<<: *coin-job
soqt-ubuntu:
ubuntu-soqt:
<<: *ubuntu-job
<<: *soqt-job
needs: ["coin-ubuntu"]
needs: ["ubuntu-coin"]
geomodelcore-ubuntu:
ubuntu-geomodelcore:
<<: *ubuntu-job
<<: *geomodelcore-job
geomodelio-ubuntu:
ubuntu-geomodelio:
<<: *ubuntu-job
<<: *geomodelio-job
needs: ["geomodelcore-ubuntu"]
geomodelvisualization-ubuntu:
<<: *ubuntu-job
<<: *geomodelvisualization-job
needs: ["coin-ubuntu", "soqt-ubuntu", "geomodelcore-ubuntu", "geomodelio-ubuntu"]
geomodelvisualization-ubuntu-standalone:
needs: ["ubuntu-geomodelcore"]
# NOTE
# The Ubuntu package 'nlohmann-json-dev' is version 2.x, too old for us.
# Thus, we now build nlohmann_json as part of the build,
# by using the 'standalone' job only
# ubuntu-gmex:
# <<: *ubuntu-job
# <<: *geomodelvisualization-job
# needs: ["ubuntu-coin", "ubuntu-soqt", "ubuntu-geomodelcore", "ubuntu-geomodelio"]
# variables:
# CMAKE_ARGS: ${CMAKE_BASE_ARGS}
ubuntu-gmex-standalone:
<<: *ubuntu-job
<<: *geomodelvisualization-job
needs: ["coin-ubuntu", "soqt-ubuntu", "geomodelcore-ubuntu", "geomodelio-ubuntu"]
needs: ["ubuntu-coin", "ubuntu-soqt", "ubuntu-geomodelcore", "ubuntu-geomodelio"]
variables:
CMAKE_ARGS: ${CMAKE_BASE_ARGS}
CMAKE_EXTRA_FLAGS: -DGEOMODEL_USE_BUILTIN_JSON=TRUE
# Set up the project.
cmake_minimum_required( VERSION 3.10 )
# set minimum C++b standard
set (CMAKE_CXX_STANDARD 14)
project( "GeoModelVisualization" VERSION 3.1.2 LANGUAGES CXX )
set ( CMAKE_BUILD_TYPE RELEASE )
set (OpenGL_GL_PREFERENCE GLVND)
# Make the module directory visible to CMake.
list( APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake )
# Use the GNU install directory names.
include( GNUInstallDirs )
# Set up the "optional" dependencies.
include( SetupJSON )
# Project's dependencies.
find_package( GeoModelCore REQUIRED )
find_package( GeoModelIO REQUIRED )
......@@ -21,4 +34,3 @@ add_subdirectory(VP1Base)
add_subdirectory(VP1HEPVis)
add_subdirectory(VP1GuideLineSystems)
......@@ -19,13 +19,15 @@ find_package( Qt5 COMPONENTS Core Gui Widgets OpenGL PrintSupport Network )
find_package( Coin REQUIRED )
find_package( SoQt REQUIRED )
find_package( nlohmann_json QUIET )
find_package(nlohmann_json QUIET)
#find_package( Qt5 COMPONENTS Core Gui Widgets Sql )
if( APPLE )
find_package(OpenGL REQUIRED)
endif()
# Find the header and source files.
file( GLOB SOURCES src/*.cxx )
file( GLOB HEADERS GXClashPointSystems/*.h )
......@@ -61,13 +63,19 @@ if ( APPLE )
target_link_directories (GXClashPointSystems PUBLIC ${Coin_LIB_DIR} )
endif()
target_link_libraries (GXClashPointSystems PRIVATE SoQt::SoQt Coin::Coin ${Qt5Core_LIBRARIES} GXGui GXBase GXHEPVis ${SoQt_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5PrintSupport_LIBRARIES} )
if( GEOMODEL_USE_BUILTIN_JSON )
add_dependencies( GXClashPointSystems JSON )
endif()
if( nlohmann_json_FOUND )
target_link_libraries (GXClashPointSystems SoQt::SoQt Coin::Coin nlohmann_json::nlohmann_json ${Qt5Core_LIBRARIES} GXGui GXBase GXHEPVis ${SoQt_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5PrintSupport_LIBRARIES} )
else()
message(STATUS "'nlohmann_json' not found by CMake!! Anyway, if you installed the single header file in a standard system include dir, I will be able to use it.")
target_link_libraries (GXClashPointSystems SoQt::SoQt Coin::Coin ${Qt5Core_LIBRARIES} GXGui GXBase GXHEPVis ${SoQt_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5PrintSupport_LIBRARIES} )
message(STATUS "dir: ${nlohmann_json_INCLUDE_DIR}")
if( nlohmann_json_FOUND OR GEOMODEL_USE_BUILTIN_JSON )
# 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')
# NOTE: Needs to be PUBLIC for the built-in nlohmann_json
target_link_libraries( GXClashPointSystems PUBLIC nlohmann_json::nlohmann_json )
endif()
add_definitions (${Qt5Core_DEFINITIONS})
......
......
......@@ -19,7 +19,7 @@
#include "VP1Base/VP1Serialise.h"
#include "VP1Base/VP1Deserialise.h"
#include "VP1Base/VP1Msg.h"
#include <QFileDialog>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoSwitch.h>
#include <Inventor/nodes/SoPointSet.h>
......@@ -30,11 +30,16 @@
#include <Inventor/nodes/SoBaseColor.h>
#include <Inventor/SbVec3f.h>
#include <QFileDialog>
#include <nlohmann/json.hpp>
#include <map>
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
class GXClashPointSystem::Imp {
......
......
# 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 "nlohmann_json" 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 "'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
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/JSONInstall/${CMAKE_INSTALL_INCLUDEDIR}" )
set( nlohmann_json_INCLUDE_DIRS "${nlohmann_json_INCLUDE_DIR}" )
message(STATUS "Installing nlohmann_json in: ${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 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 to comment