From 07dbff7a713c66c45a2403b5c4e359b4bbbb764b Mon Sep 17 00:00:00 2001
From: Andre Sailer <andre.philippe.sailer@cern.ch>
Date: Tue, 20 Aug 2019 11:40:55 +0200
Subject: [PATCH] Examples: cleanup CmakeLists

---
 examples/AlignDet/CMakeLists.txt        | 11 ++++-------
 examples/CMakeLists.txt                 |  2 --
 examples/ClientTests/CMakeLists.txt     | 17 +++++++----------
 examples/Conditions/CMakeLists.txt      | 15 ++++++---------
 examples/DDG4/CMakeLists.txt            |  1 -
 examples/DDG4_MySensDet/CMakeLists.txt  |  3 ---
 examples/LHeD/CMakeLists.txt            |  4 ----
 examples/OpticalSurfaces/CMakeLists.txt |  8 ++------
 examples/Persistency/CMakeLists.txt     |  7 ++++---
 examples/SimpleDetector/CMakeLists.txt  |  8 ++++----
 10 files changed, 27 insertions(+), 49 deletions(-)

diff --git a/examples/AlignDet/CMakeLists.txt b/examples/AlignDet/CMakeLists.txt
index 6c7282fec..98f7286d5 100644
--- a/examples/AlignDet/CMakeLists.txt
+++ b/examples/AlignDet/CMakeLists.txt
@@ -14,14 +14,11 @@ include ( ${DD4hep_DIR}/cmake/DD4hep.cmake )
 #--------------------------------------------------------------------------
 dd4hep_configure_output()
 
-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)
+dd4hep_add_plugin(AlignDetExample SOURCES src/*.cpp
+  USES DD4hep::DDCore DD4hep::DDCond DD4hep::DDAlign
+       ROOT::Core ROOT::Geom ROOT::GenVector ROOT::MathCore
+  )
 dd4hep_install_dir(compact DESTINATION ${AlignDet_INSTALL})
 dd4hep_configure_scripts(AlignDet DEFAULT_SETUP WITH_TESTS)
 install(TARGETS AlignDetExample LIBRARY DESTINATION lib)
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index adcbed9a5..9e6da72e5 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -45,8 +45,6 @@ SET( ENV{DD4hepExamplesINSTALL} ${CMAKE_INSTALL_PREFIX} )
 #
 dd4hep_configure_output()
 
-find_package(ROOT REQUIRED COMPONENTS Geom GenVector)
-
 add_subdirectory(CLICSiD)
 add_subdirectory(LHeD)
 add_subdirectory(AlignDet)
diff --git a/examples/ClientTests/CMakeLists.txt b/examples/ClientTests/CMakeLists.txt
index 148d1ec26..882e64fbf 100644
--- a/examples/ClientTests/CMakeLists.txt
+++ b/examples/ClientTests/CMakeLists.txt
@@ -14,15 +14,8 @@ include ( ${DD4hep_DIR}/cmake/DD4hep.cmake )
 #--------------------------------------------------------------------------
 dd4hep_configure_output()
 
-link_libraries(
-  DD4hep::DDCore
-  DD4hep::DDCond
-  DD4hep::DDAlign
-  ROOT::Core ROOT::Geom ROOT::GenVector
-  )
-
 if(TARGET XercesC::XercesC)
-  link_libraries(XercesC::XercesC)
+  SET(OPT_XERCESC XercesC::XercesC)
 endif()
 
 include_directories(./include)
@@ -31,13 +24,17 @@ if(TARGET Boost::boost)
   SET(CT_BOOST_SOURCES src_boost/*.cpp)
   set(CT_BOOST_LIB Boost::boost)
 endif()
-dd4hep_add_plugin(ClientTests SOURCES src/*.cpp ${CT_BOOST_SOURCES}) 
-target_link_libraries(ClientTests ${CT_BOOST_LIB})
+dd4hep_add_plugin(ClientTests SOURCES src/*.cpp ${CT_BOOST_SOURCES}
+  USES DD4hep::DDCore DD4hep::DDCond DD4hep::DDAlign
+       ROOT::Core ROOT::Geom ROOT::GenVector
+       ${OPT_XERCESC} ${CT_BOOST_LIB}
+  )
 install(TARGETS ClientTests LIBRARY DESTINATION lib)
 
 #
 #-----------------------------------------------------------------------------------
 add_executable( multipleGeo   main/MultipleGeometries.cpp )
+target_link_libraries(multipleGeo DD4hep::DDCore DD4hep::DDCond DD4hep::DDAlign)
 install(TARGETS multipleGeo RUNTIME DESTINATION bin)
 #-----------------------------------------------------------------------------------
 #
diff --git a/examples/Conditions/CMakeLists.txt b/examples/Conditions/CMakeLists.txt
index c84e4f533..1ac8290fa 100644
--- a/examples/Conditions/CMakeLists.txt
+++ b/examples/Conditions/CMakeLists.txt
@@ -15,18 +15,15 @@ include ( ${DD4hep_DIR}/cmake/DD4hep.cmake )
 dd4hep_configure_output ()
 
 if(TARGET XercesC::XercesC)
-  link_libraries(XercesC::XercesC)
+  SET(OPT_XERCESC XercesC::XercesC)
 endif()
-
-link_libraries(
-  DD4hep::DDCore
-  DD4hep::DDCond
-  DD4hep::DDAlign
-  ROOT::Core ROOT::Geom ROOT::GenVector
-  )
   
 #-----------------------------------------------------------------------------------
-dd4hep_add_plugin(ConditionsExample SOURCES src/*.cpp)
+dd4hep_add_plugin(ConditionsExample SOURCES src/*.cpp
+  USES  DD4hep::DDCore DD4hep::DDCond DD4hep::DDAlign
+        ROOT::Core ROOT::Geom ROOT::GenVector
+        ${OPT_XERCESC}
+  )
 install(TARGETS ConditionsExample LIBRARY DESTINATION lib)
 dd4hep_install_dir( xml  DESTINATION examples/Conditions )
 dd4hep_install_dir( data DESTINATION examples/Conditions )
diff --git a/examples/DDG4/CMakeLists.txt b/examples/DDG4/CMakeLists.txt
index 9617ea939..a9297b1f4 100644
--- a/examples/DDG4/CMakeLists.txt
+++ b/examples/DDG4/CMakeLists.txt
@@ -13,7 +13,6 @@ include ( ${DD4hep_DIR}/cmake/DD4hep.cmake )
 
 #-----------------------------------------------------------------------------------
 dd4hep_configure_output ()
-link_libraries(DD4hep::DDCore)
 
 set(DDG4examples_INSTALL  ${CMAKE_INSTALL_PREFIX}/examples/DDG4)
 #
diff --git a/examples/DDG4_MySensDet/CMakeLists.txt b/examples/DDG4_MySensDet/CMakeLists.txt
index 8e29086f0..51888b8aa 100644
--- a/examples/DDG4_MySensDet/CMakeLists.txt
+++ b/examples/DDG4_MySensDet/CMakeLists.txt
@@ -16,9 +16,6 @@ if(NOT TARGET Geant4::Interface)
   return()
 endif()
 
-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)
 install(DIRECTORY scripts DESTINATION ${DDG4_MySensDet_INSTALL})
diff --git a/examples/LHeD/CMakeLists.txt b/examples/LHeD/CMakeLists.txt
index c716a48ac..4fb8552a8 100644
--- a/examples/LHeD/CMakeLists.txt
+++ b/examples/LHeD/CMakeLists.txt
@@ -13,10 +13,6 @@ include ( ${DD4hep_DIR}/cmake/DD4hep.cmake )
 
 #-----------------------------------------------------------------------------------
 dd4hep_configure_output ()
-# dd4hep_package ( LHeD MAJOR 0 MINOR 0 PATCH 1
-#   USES           [ROOT   REQUIRED COMPONENTS Geom GenVector MathCore] 
-#                  [DD4hep REQUIRED COMPONENTS DDRec DDCore DDCond DDAlign]
-#   )
 set(LHeDEx_INSTALL         ${CMAKE_INSTALL_PREFIX}/examples/LHeD)
 dd4hep_install_dir( src compact scripts sim DESTINATION ${LHeDEx_INSTALL} )
 #-----------------------------------------------------------------------------------
diff --git a/examples/OpticalSurfaces/CMakeLists.txt b/examples/OpticalSurfaces/CMakeLists.txt
index b41e6be10..e92ae0a07 100644
--- a/examples/OpticalSurfaces/CMakeLists.txt
+++ b/examples/OpticalSurfaces/CMakeLists.txt
@@ -22,13 +22,9 @@ dd4hep_print("|++> Building optical surface test")
 #--------------------------------------------------------------------------
 dd4hep_configure_output()
 
-link_libraries(
-  DD4hep::DDCore DD4hep::DDCond
-  ROOT::Core ROOT::Geom ROOT::GenVector ROOT::MathCore
-  )
-
 set(OpticalSurfaces_INSTALL ${CMAKE_INSTALL_PREFIX}/examples/OpticalSurfaces)
-dd4hep_add_plugin(OpticalSurfacesExample SOURCES src/*.cpp  )
+dd4hep_add_plugin(OpticalSurfacesExample SOURCES src/*.cpp
+  USES DD4hep::DDCore DD4hep::DDCond ROOT::Core ROOT::Geom ROOT::GenVector ROOT::MathCore)
 install(TARGETS OpticalSurfacesExample LIBRARY DESTINATION lib)
 install(DIRECTORY compact scripts DESTINATION ${OpticalSurfaces_INSTALL} )
 dd4hep_configure_scripts( OpticalSurfaces DEFAULT_SETUP WITH_TESTS)
diff --git a/examples/Persistency/CMakeLists.txt b/examples/Persistency/CMakeLists.txt
index 68904d920..5eda33742 100644
--- a/examples/Persistency/CMakeLists.txt
+++ b/examples/Persistency/CMakeLists.txt
@@ -11,13 +11,14 @@
 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)
+  SET(OPT_XERCESC XercesC::XercesC)
 endif()
 
 #-----------------------------------------------------------------------------------
-dd4hep_add_plugin(PersistencyExample SOURCES src/*.cpp)
+dd4hep_add_plugin(PersistencyExample SOURCES src/*.cpp
+  USES DD4hep::DDCore ROOT::Core ROOT::Geom ROOT::GenVector ${OPT_XERCESC}
+  )
 install(TARGETS PersistencyExample LIBRARY DESTINATION lib)
 dd4hep_configure_scripts (Persistency DEFAULT_SETUP WITH_TESTS )
 #--------------------------------------------------------------------------
diff --git a/examples/SimpleDetector/CMakeLists.txt b/examples/SimpleDetector/CMakeLists.txt
index feecea3a8..8214d2ecb 100644
--- a/examples/SimpleDetector/CMakeLists.txt
+++ b/examples/SimpleDetector/CMakeLists.txt
@@ -12,13 +12,13 @@ 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)
+  SET(OPT_XERCESC XercesC::XercesC)
 endif()
 
-dd4hep_add_plugin(SimpleDetector SOURCES src/*.cpp)
+dd4hep_add_plugin(SimpleDetector SOURCES src/*.cpp
+  USES DD4hep::DDCore DD4hep::DDRec ROOT::Core ROOT::Geom ROOT::GenVector ${OPT_XERCESC}
+  )
 install(TARGETS SimpleDetector LIBRARY DESTINATION lib)
 install(DIRECTORY compact DESTINATION examples/ClientTests)
 #-----------------------------------------------------------------------------------
-- 
GitLab