From c3f46406d9f06b233f15da7a381b56f43c61ac40 Mon Sep 17 00:00:00 2001
From: Ben Couturier <ben.couturier@cern.ch>
Date: Tue, 24 Nov 2015 15:55:09 +0100
Subject: [PATCH] Added cached variables for SRCS_REPOSITORY and GEANT4_TAG

---
 CMakeLists.txt                 |  2 ++
 Geant4/G4config/CMakeLists.txt | 35 ++++++++++++++++++----------------
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d54ae44..8a14f06 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,6 +2,8 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8.5)
 
 # NO_NINJA : Geant4 build fails with Ninja
 
+set(GEANT4_SRCS_REPOSITORY https://gitlab.cern.ch/lhcb/Geant4-srcs.git CACHE STRING "Repository for Geant4 sources")
+
 find_package(GaudiProject)
 gaudi_project(Geant4 v96r4p3
               DATA Geant4Files VERSION v96r*)
diff --git a/Geant4/G4config/CMakeLists.txt b/Geant4/G4config/CMakeLists.txt
index 27c43cf..7145788 100644
--- a/Geant4/G4config/CMakeLists.txt
+++ b/Geant4/G4config/CMakeLists.txt
@@ -21,29 +21,32 @@ else()
   set(G4DATA ../share)
 endif()
 
-if(DEFINED ENV{G4_NATIVE_VERSION})
-  set(Geant4_tag $ENV{G4_NATIVE_VERSION})
-  if(NOT Geant4_tag MATCHES "^4\\.")
-    # G4_NATIVE_VERSION might not contain the initial '4.' that we need
-    # see https://its.cern.ch/jira/browse/LHCBGAUSS-43
-    set(Geant4_tag 4.${Geant4_tag})
+if (NOT GEANT4_TAG)
+  if(DEFINED ENV{G4_NATIVE_VERSION})
+    set(GEANT4_TAG $ENV{G4_NATIVE_VERSION})
+    if(NOT GEANT4_TAG MATCHES "^4\\.")
+      # G4_NATIVE_VERSION might not contain the initial '4.' that we need
+      # see https://its.cern.ch/jira/browse/LHCBGAUSS-43
+      set(GEANT4_TAG 4.${GEANT4_TAG})
+    endif()
+    if(NOT GEANT4_TAG MATCHES "^geant")
+      set(GEANT4_TAG geant${GEANT4_TAG})
+    endif()
+  else()
+    set(GEANT4_TAG ${CMAKE_PROJECT_VERSION})
   endif()
-  if(NOT Geant4_tag MATCHES "^geant")
-    set(Geant4_tag geant${Geant4_tag})
+  # Special mapping of version HEAD
+  if(GEANT4_TAG STREQUAL "HEAD")
+    set(GEANT4_TAG master)
   endif()
-else()
-  set(Geant4_tag ${CMAKE_PROJECT_VERSION})
-endif()
-# Special mapping of version HEAD
-if(Geant4_tag STREQUAL "HEAD")
-  set(Geant4_tag master)
+  set(GEANT4_TAG ${GEANT4_TAG} CACHE STRING "Tag of Geant4 to get from the Geant4-srcs repository")
 endif()
 
 include(ExternalProject)
 
 ExternalProject_Add(Geant4
-   GIT_REPOSITORY https://gitlab.cern.ch/lhcb/Geant4-srcs.git
-   GIT_TAG ${Geant4_tag}
+   GIT_REPOSITORY ${GEANT4_SRCS_REPOSITORY}
+   GIT_TAG ${GEANT4_TAG}
    CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_SOURCE_DIR}/toolchain.cmake
               -DGEANT4_BUILD_CXXSTD=${GAUDI_CXX_STANDARD}
               -DGEANT4_INSTALL_DATA=OFF
-- 
GitLab