From 19e4eebbcc02dd8fff1ba3ae896d5e840eb94aa0 Mon Sep 17 00:00:00 2001
From: adrien-matta <a.matta@surrey.ac.uk>
Date: Fri, 5 Feb 2016 10:13:32 +0000
Subject: [PATCH] * Allow compilation with Geant4 9.x         - Skip the
 missing include depending on G4 version

---
 NPSimulation/CMakeLists.txt      | 19 ++++++++++++++++++-
 NPSimulation/Core/PhysicsList.cc | 10 ++++++++--
 NPSimulation/Core/PhysicsList.hh |  2 ++
 3 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/NPSimulation/CMakeLists.txt b/NPSimulation/CMakeLists.txt
index 5d36cb668..78556f656 100644
--- a/NPSimulation/CMakeLists.txt
+++ b/NPSimulation/CMakeLists.txt
@@ -16,8 +16,22 @@ set(CMAKE_INSTALL_MESSAGE LAZY)
 
 # Finding Geant 4
 find_package(Geant4 REQUIRED ui_all vis_all)
-message(${Geant4_USE_FILE})
+
+# Rely on name of the file to set the version  
+string(REGEX MATCH "Geant4-*.*.*/" G4Version "${Geant4_USE_FILE}")
+string(REPLACE "Geant4-" "" G4Version "${G4Version}")
+string(REPLACE "/" "" G4Version "${G4Version}")
+string(FIND "${G4Version}" "." pos)
+string(SUBSTRING "${G4Version}" "0" "${pos}" NPS_GEANT4_VERSION_MAJOR)
+string(REPLACE "${NPS_GEANT4_VERSION_MAJOR}." "" G4Version "${G4Version}")
+string(FIND "${G4Version}" "." pos)
+string(SUBSTRING "${G4Version}" "0" "${pos}" NPS_GEANT4_VERSION_MINOR)
+string(REPLACE "${NPS_GEANT4_VERSION_MINOR}." "" G4Version "${G4Version}")
+set(NPS_GEANT4_VERSION_PATCH "${G4Version}")
+message ("Geant4 found, Version : ${NPS_GEANT4_VERSION_MAJOR}.${NPS_GEANT4_VERSION_MINOR}.${NPS_GEANT4_VERSION_PATCH}")
+
 include(${Geant4_USE_FILE}) 
+add_definitions(${Geant4_DEFINITIONS})    
 
 # Finding NPLib
 find_package(NPLib)
@@ -75,6 +89,9 @@ if(Geant4_gdml_FOUND)
 endif()
 
 
+# set the Geant4 version info
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNPS_GEANT4_VERSION_MAJOR=${NPS_GEANT4_VERSION_MAJOR}") 
+
 # If the compiler is Clang, silence the unrecognised flags
 if(${CMAKE_CXX_COMPILER_ID} MATCHES ".*Clang.*")
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -fcolor-diagnostics -Wno-deprecated-register -Wno-shadow")
diff --git a/NPSimulation/Core/PhysicsList.cc b/NPSimulation/Core/PhysicsList.cc
index c5048cbb0..d5103c602 100644
--- a/NPSimulation/Core/PhysicsList.cc
+++ b/NPSimulation/Core/PhysicsList.cc
@@ -85,9 +85,15 @@ PhysicsList::PhysicsList() : G4VModularPhysicsList(){
   if(m_StoppingPhysics)
     m_PhysList["StoppingPhysics"]=new G4StoppingPhysics();
 
-  if(m_HadronPhysicsQGSP_BIC_HP)
-    m_PhysList["HadronPhysicsQGSP_BIC_HP"] = new G4HadronPhysicsQGSP_BIC_HP();
+  if(m_HadronPhysicsQGSP_BIC_HP){
+    #if NPS_GEANT4_VERSION_MAJOR > 9
+      m_PhysList["HadronPhysicsQGSP_BIC_HP"] = new G4HadronPhysicsQGSP_BIC_HP();
+    #else
+      std::cout << "\r\032[1;31m Warning: physics list HadronPhysicsQGSP_BIC_HP require Geant4 10, process not activated \033[0m" <<std::endl;  
+    #endif
 
+    m_PhysList["HadronPhysicsQGSP_BIC_HP"] = new G4HadronPhysicsQGSP_BIC_HP();
+  }
   // Optical Photon for scintillator simulation
     if(m_OpticalPhysics){
         opticalPhysicsList = new G4OpticalPhysics(0);
diff --git a/NPSimulation/Core/PhysicsList.hh b/NPSimulation/Core/PhysicsList.hh
index be3f65716..f263cf638 100644
--- a/NPSimulation/Core/PhysicsList.hh
+++ b/NPSimulation/Core/PhysicsList.hh
@@ -56,7 +56,9 @@
 #include "G4HadronElasticPhysics.hh"
 #include "G4HadronElasticPhysicsHP.hh"
 #include "G4IonBinaryCascadePhysics.hh"
+#if NPS_GEANT4_VERSION_MAJOR > 9
 #include "G4HadronPhysicsQGSP_BIC_HP.hh"
+#endif
 #include "G4HadronPhysicsQGSP_BIC.hh"
 class G4VPhysicsConstructor;
 
-- 
GitLab