From f915bfdf8dee1aaebd6c07e8c0f150556a689d06 Mon Sep 17 00:00:00 2001
From: Andre Sailer <andre.philippe.sailer@cern.ch>
Date: Mon, 19 Aug 2019 18:52:08 +0200
Subject: [PATCH] Examples: fix order of linking against libraries to avoid
 picking up old dd4hep headers from lcg installation

---
 examples/AlignDet/CMakeLists.txt               |  3 ++-
 examples/ClientTests/CMakeLists.txt            | 12 +++++++-----
 examples/Conditions/CMakeLists.txt             |  3 ++-
 examples/DDCMS/CMakeLists.txt                  |  2 +-
 examples/DDDigi/CMakeLists.txt                 |  3 +--
 examples/DDG4_MySensDet/CMakeLists.txt         |  6 +++---
 examples/LHeD/CMakeLists.txt                   |  3 +--
 examples/LHeD/src/Lhe_BeamPipe_Central_geo.cpp |  2 +-
 examples/Persistency/CMakeLists.txt            |  2 +-
 examples/SimpleDetector/CMakeLists.txt         |  4 ++--
 10 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/examples/AlignDet/CMakeLists.txt b/examples/AlignDet/CMakeLists.txt
index 06a9d3106..6c7282fec 100644
--- a/examples/AlignDet/CMakeLists.txt
+++ b/examples/AlignDet/CMakeLists.txt
@@ -14,10 +14,11 @@ include ( ${DD4hep_DIR}/cmake/DD4hep.cmake )
 #--------------------------------------------------------------------------
 dd4hep_configure_output()
 
-link_libraries(ROOT::Core ROOT::Geom ROOT::GenVector ROOT::MathCore
+link_libraries(
   DD4hep::DDCore
   DD4hep::DDCond
   DD4hep::DDAlign
+  ROOT::Core ROOT::Geom ROOT::GenVector ROOT::MathCore
   )
 set(AlignDet_INSTALL ${CMAKE_INSTALL_PREFIX}/examples/AlignDet)
 dd4hep_add_plugin(AlignDetExample SOURCES src/*.cpp)
diff --git a/examples/ClientTests/CMakeLists.txt b/examples/ClientTests/CMakeLists.txt
index 4c25334c3..148d1ec26 100644
--- a/examples/ClientTests/CMakeLists.txt
+++ b/examples/ClientTests/CMakeLists.txt
@@ -14,15 +14,17 @@ include ( ${DD4hep_DIR}/cmake/DD4hep.cmake )
 #--------------------------------------------------------------------------
 dd4hep_configure_output()
 
-if(TARGET XercesC::XercesC)
-  link_libraries(XercesC::XercesC)
-endif()
-
-link_libraries(ROOT::Core ROOT::Geom ROOT::GenVector
+link_libraries(
   DD4hep::DDCore
   DD4hep::DDCond
   DD4hep::DDAlign
+  ROOT::Core ROOT::Geom ROOT::GenVector
   )
+
+if(TARGET XercesC::XercesC)
+  link_libraries(XercesC::XercesC)
+endif()
+
 include_directories(./include)
 #--------------------------------------------------------------------------
 if(TARGET Boost::boost)
diff --git a/examples/Conditions/CMakeLists.txt b/examples/Conditions/CMakeLists.txt
index 0ad6eec52..c84e4f533 100644
--- a/examples/Conditions/CMakeLists.txt
+++ b/examples/Conditions/CMakeLists.txt
@@ -18,10 +18,11 @@ if(TARGET XercesC::XercesC)
   link_libraries(XercesC::XercesC)
 endif()
 
-link_libraries(ROOT::Core ROOT::Geom ROOT::GenVector
+link_libraries(
   DD4hep::DDCore
   DD4hep::DDCond
   DD4hep::DDAlign
+  ROOT::Core ROOT::Geom ROOT::GenVector
   )
   
 #-----------------------------------------------------------------------------------
diff --git a/examples/DDCMS/CMakeLists.txt b/examples/DDCMS/CMakeLists.txt
index 819df9acb..453209939 100644
--- a/examples/DDCMS/CMakeLists.txt
+++ b/examples/DDCMS/CMakeLists.txt
@@ -48,7 +48,7 @@ endif()
 #
 #---DDCMS plugin library -------------------------------------------------------
 dd4hep_add_plugin ( DDCMS SOURCES src/*.cpp src/plugins/*.cpp
-  USES DD4hep::DDCore DD4hep::DDAlign DD4hep::DDCond ROOT::Core ROOT::Geom ROOT::GenVector
+  USES DD4hep::DDParsers DD4hep::DDCore DD4hep::DDAlign DD4hep::DDCond ROOT::Core ROOT::Geom ROOT::GenVector
   )
 install(TARGETS DDCMS LIBRARY DESTINATION lib)
 target_include_directories(DDCMS PUBLIC include)
diff --git a/examples/DDDigi/CMakeLists.txt b/examples/DDDigi/CMakeLists.txt
index 5320c7609..a313599cc 100644
--- a/examples/DDDigi/CMakeLists.txt
+++ b/examples/DDDigi/CMakeLists.txt
@@ -14,13 +14,12 @@ include ( ${DD4hep_DIR}/cmake/DD4hep.cmake )
 #-----------------------------------------------------------------------------------
 dd4hep_configure_output ()
 
-link_libraries(DD4hep::DDDigi)
 set(DDDigiexamples_INSTALL  ${CMAKE_INSTALL_PREFIX}/examples/DDDigi)
 #
 dd4hep_set_compiler_flags()
 #
 dd4hep_add_plugin(DDDigiExampleLib SOURCES src/*.cpp )
-target_link_libraries(DDDigiExampleLib Boost::boost ROOT::Geom ROOT::GenVector ROOT::RIO)
+target_link_libraries(DDDigiExampleLib DD4hep::DDDigi Boost::boost ROOT::Geom ROOT::GenVector ROOT::RIO)
 install(TARGETS DDDigiExampleLib LIBRARY DESTINATION lib)
 install(DIRECTORY scripts DESTINATION ${DDDigiexamples_INSTALL})
 #
diff --git a/examples/DDG4_MySensDet/CMakeLists.txt b/examples/DDG4_MySensDet/CMakeLists.txt
index ff15daa9d..8e29086f0 100644
--- a/examples/DDG4_MySensDet/CMakeLists.txt
+++ b/examples/DDG4_MySensDet/CMakeLists.txt
@@ -16,8 +16,8 @@ if(NOT TARGET Geant4::Interface)
   return()
 endif()
 
-link_libraries(Geant4::Interface ROOT::Core ROOT::Geom ROOT::GenVector ROOT::RIO
-  DD4hep::DDCore DD4hep::DDG4)
+link_libraries(DD4hep::DDCore DD4hep::DDG4 Geant4::Interface ROOT::Core ROOT::Geom ROOT::GenVector ROOT::RIO)
+
 
 #-----------------------------------------------------------------------------------
 set(DDG4_MySensDet_INSTALL ${CMAKE_INSTALL_PREFIX}/examples/DDG4_MySensDet)
@@ -39,7 +39,7 @@ if (DD4HEP_USE_GEANT4)
   dd4hep_add_plugin( DDG4_MySensDet
     GENERATED G__DDG4_MySensDet.cxx
     SOURCES   src/*.cpp
-    USES      Geant4::Interface ROOT::Core ROOT::Geom ROOT::GenVector ROOT::RIO DD4hep::DDCore DD4hep::DDG4
+    USES      DD4hep::DDCore DD4hep::DDG4 Geant4::Interface ROOT::Core ROOT::Geom ROOT::GenVector ROOT::RIO
     )
   install(TARGETS DDG4_MySensDet DESTINATION lib)
   
diff --git a/examples/LHeD/CMakeLists.txt b/examples/LHeD/CMakeLists.txt
index a0620ab50..c716a48ac 100644
--- a/examples/LHeD/CMakeLists.txt
+++ b/examples/LHeD/CMakeLists.txt
@@ -25,11 +25,10 @@ set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
 
 dd4hep_add_plugin(LHeD
   SOURCES src/*.cpp
-  USES  ROOT::Core ROOT::Geom ROOT::GenVector DD4hep::DDRec DD4hep::DDCore DD4hep::DDCond DD4hep::DDAlign
+  USES    DD4hep::DDRec DD4hep::DDCore DD4hep::DDCond DD4hep::DDAlign ROOT::Core ROOT::Geom ROOT::GenVector 
   )
 
 if (DD4HEP_USE_GEANT4)
-  find_package(Geant4 REQUIRED)
   add_executable(LHeDXML scripts/LHeDXML.C)
   target_link_libraries(LHeDXML DD4hep::DDCore DD4hep::DDG4 Geant4::Interface)
   #--------------------------------------------------------------------------
diff --git a/examples/LHeD/src/Lhe_BeamPipe_Central_geo.cpp b/examples/LHeD/src/Lhe_BeamPipe_Central_geo.cpp
index 977d22962..8afc22bb4 100644
--- a/examples/LHeD/src/Lhe_BeamPipe_Central_geo.cpp
+++ b/examples/LHeD/src/Lhe_BeamPipe_Central_geo.cpp
@@ -106,7 +106,7 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
   DetElement sdet (name,x_det.id());
   Material   mat  (description.material(x_det.materialStr()));
   //  vector<double> rmin,rmax,z,thickness;
-  double rmin, rmax, thickness, z;
+  double rmin, rmax, thickness, z=0.0;
   //  PlacedVolume pv;
 
   // multiplication factor for ellipse major radius
diff --git a/examples/Persistency/CMakeLists.txt b/examples/Persistency/CMakeLists.txt
index b148f353b..68904d920 100644
--- a/examples/Persistency/CMakeLists.txt
+++ b/examples/Persistency/CMakeLists.txt
@@ -11,10 +11,10 @@
 cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
 include ( ${DD4hep_DIR}/cmake/DD4hep.cmake )
 
+link_libraries(DD4hep::DDCore ROOT::Core ROOT::Geom ROOT::GenVector)
 if(TARGET XercesC::XercesC)
   link_libraries(XercesC::XercesC)
 endif()
-link_libraries(ROOT::Core ROOT::Geom ROOT::GenVector DD4hep::DDCore)
 
 #-----------------------------------------------------------------------------------
 dd4hep_add_plugin(PersistencyExample SOURCES src/*.cpp)
diff --git a/examples/SimpleDetector/CMakeLists.txt b/examples/SimpleDetector/CMakeLists.txt
index 2b54a46fd..feecea3a8 100644
--- a/examples/SimpleDetector/CMakeLists.txt
+++ b/examples/SimpleDetector/CMakeLists.txt
@@ -12,12 +12,12 @@ cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
 include ( ${DD4hep_DIR}/cmake/DD4hep.cmake )
 
 #-----------------------------------------------------------------------------------
+link_libraries(DD4hep::DDCore DD4hep::DDRec ROOT::Core ROOT::Geom ROOT::GenVector)
+
 if(TARGET XercesC::XercesC)
   link_libraries(XercesC::XercesC)
 endif()
 
-link_libraries(ROOT::Core ROOT::Geom ROOT::GenVector DD4hep::DDCore DD4hep::DDRec)
-
 dd4hep_add_plugin(SimpleDetector SOURCES src/*.cpp)
 install(TARGETS SimpleDetector LIBRARY DESTINATION lib)
 install(DIRECTORY compact DESTINATION examples/ClientTests)
-- 
GitLab