From 6306b41d2cedba255a41b83f05d88e0a4f644ab0 Mon Sep 17 00:00:00 2001
From: Riccardo Maria Bianchi <riccardo.maria.bianchi@cern.ch>
Date: Fri, 13 Nov 2020 17:58:47 +0100
Subject: [PATCH] Fix built-in JSON cmake config when building all subprojects

---
 FullSimLight/CMakeLists.txt          |  8 +++++---
 GeoModelG4/CMakeLists.txt            | 12 +++++++-----
 GeoModelVisualization/CMakeLists.txt |  8 +++++---
 3 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/FullSimLight/CMakeLists.txt b/FullSimLight/CMakeLists.txt
index bf9736748..a037d9a44 100644
--- a/FullSimLight/CMakeLists.txt
+++ b/FullSimLight/CMakeLists.txt
@@ -17,9 +17,11 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
     include( configure_cpp_options )
     set( CMAKE_FIND_FRAMEWORK "LAST" CACHE STRING
          "Framework finding behaviour on macOS" )
-    # Set up how the project handle some of its dependenices. Either by picking them
-    # up from the environment, or building them itself.
-    include( SetupJSON )
+    if( NOT TARGET JSONExt )
+        # Set up how the project handle some of its dependenices. Either by picking them
+        # up from the environment, or building them itself.
+        include( SetupJSON )
+    endif()
     # Find the base GeoModel packages, which must be installed on the target system already
     find_package( GeoModelCore REQUIRED 4.0.0 ) #TODO: the version should be se in the root folder
     find_package( GeoModelIO REQUIRED 4.0.0 ) #TODO: the version should be se in the root folder
diff --git a/GeoModelG4/CMakeLists.txt b/GeoModelG4/CMakeLists.txt
index 5e8935924..c52ec63b4 100644
--- a/GeoModelG4/CMakeLists.txt
+++ b/GeoModelG4/CMakeLists.txt
@@ -2,8 +2,8 @@
 cmake_minimum_required( VERSION 3.1 )
 project( "GeoModelG4" VERSION 1.1.0 LANGUAGES CXX )
 
-message("CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}")
-message("PROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}")
+#message("CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}") # debug msg
+#message("PROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}") # debug msg
 if( (CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) OR GEOMODEL_BUILD_GEOMODELG4 )
     # I am top-level project.
     # Make the root module directory visible to CMake.
@@ -16,9 +16,11 @@ if( (CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) OR GEOMODEL_BUILD_GEOMODELG4
     include( configure_cpp_options )
     set( CMAKE_FIND_FRAMEWORK "LAST" CACHE STRING
          "Framework finding behaviour on macOS" )
-    # Set up how the project handle some of its dependenices. Either by picking them
-    # up from the environment, or building them itself.^[[?12;4$y
-    include( SetupJSON )
+    if( NOT TARGET JSONExt )
+        # Set up how the project handle some of its dependenices. Either by picking them
+        # up from the environment, or building them itself.
+        include( SetupJSON )
+    endif()
     # Find the base GeoModel packages, which must be installed on the target system already
     find_package( GeoModelCore REQUIRED 4.0.0 ) #TODO: the version should be se in the root folder
     # Set a flag to steer the  of the subpackages
diff --git a/GeoModelVisualization/CMakeLists.txt b/GeoModelVisualization/CMakeLists.txt
index 52f5200f7..92888e94d 100644
--- a/GeoModelVisualization/CMakeLists.txt
+++ b/GeoModelVisualization/CMakeLists.txt
@@ -19,9 +19,11 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
     include( configure_cpp_options )
     set( CMAKE_FIND_FRAMEWORK "LAST" CACHE STRING
          "Framework finding behaviour on macOS" )
-    # Set up how the project handle some of its dependenices. Either by picking them
-    # up from the environment, or building them itself.
-    include( SetupJSON )
+    if( NOT TARGET JSONExt )
+        # Set up how the project handle some of its dependenices. Either by picking them
+        # up from the environment, or building them itself.
+        include( SetupJSON )
+    endif()
     # Find the base GeoModel packages, which must be installed on the target system already
     find_package( GeoModelCore REQUIRED 4.0.0 ) #TODO: the version should be se in the root folder
     find_package( GeoModelIO REQUIRED 4.0.0 ) #TODO: the version should be se in the root folder
-- 
GitLab