From 4a5edb187d2982c317e6265f285d62373ab51cc5 Mon Sep 17 00:00:00 2001
From: Frank Gaede <frank.gaede@desy.de>
Date: Tue, 15 Jul 2014 16:30:17 +0000
Subject: [PATCH]  - made building of DDSegmentation before DD4hep optional   
 in order to keep simple build sequence for DD4hep

---
 CMakeLists.txt        | 13 +++++++++++--
 DDCore/CMakeLists.txt | 12 ++++++------
 DDRec/CMakeLists.txt  | 14 +++++++-------
 ReadMe.txt            |  4 ++--
 4 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 454c2242b..48c55c05c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -66,10 +66,19 @@ IF( INSTALL_DOC )
 ENDIF()
 
 
-find_package(DDSegmentation REQUIRED)
+#------ allow to use a pre-built DDSegmentation  ----------------------------
+
+find_package(DDSegmentation QUIET)
+
+#if it does not exist, simply build DDSegmentation as part of DD4hep:
+if( NOT DDSegmentation_FOUND ) 
+  add_subdirectory(DDSegmentation)
+  SET( DDSegmentation_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/DDSegmentation/include)
+  SET( DDSegmentation_LIBRARIES DDSegmentation)
+endif()
 
 #---Packages------------------------------------------------------------------------
-#add_subdirectory(DDSegmentation)
+
 add_subdirectory(DDCore)
 add_subdirectory(DDSurfaces)
 add_subdirectory(DDRec)
diff --git a/DDCore/CMakeLists.txt b/DDCore/CMakeLists.txt
index 9c80a0504..459c38812 100644
--- a/DDCore/CMakeLists.txt
+++ b/DDCore/CMakeLists.txt
@@ -22,11 +22,11 @@ else()
   file(GLOB parser_sources )
 endif()
 
-# Find the DDSegmentation libraries
-find_library(DDSegmentation_LIBS
-  NAMES ${DDSegmentation_LIBRARIES}
-  PATHS ${DDSegmentation_LIBRARY_DIR}
-)
+## Find the DDSegmentation libraries
+#find_library(DDSegmentation_LIBS
+#  NAMES ${DDSegmentation_LIBRARIES}
+#  PATHS ${DDSegmentation_LIBRARY_DIR}
+#)
 
 file(GLOB headers include/DD4hep/*.h)
 file(GLOB internal_headers include/DD4hep/objects/*.h)
@@ -48,7 +48,7 @@ include(DD4hep_XML_setup)
 
 add_library(DD4hepCore SHARED ${sources} ${parser_sources} )
 
-target_link_libraries(DD4hepCore ${ROOT_LIBRARIES} ${XML_LIBRARIES} ${DDSegmentation_LIBS} Geom Reflex ${libraries})
+target_link_libraries(DD4hepCore ${ROOT_LIBRARIES} ${XML_LIBRARIES} ${DDSegmentation_LIBRARIES} Geom Reflex ${libraries})
 
 add_library(DD4hepPlugins SHARED ${plugin_sources})
 target_link_libraries(DD4hepPlugins ${ROOT_LIBRARIES} ${XML_LIBRARIES} DD4hepCore Geom Reflex ${libraries})
diff --git a/DDRec/CMakeLists.txt b/DDRec/CMakeLists.txt
index 2a0ea9dd8..8800bd0bf 100644
--- a/DDRec/CMakeLists.txt
+++ b/DDRec/CMakeLists.txt
@@ -26,14 +26,14 @@ endif()
 
 add_library(DD4hepRec SHARED ${sources} )
 
-# Find the DDSegmentation libraries
-find_library(DDSegmentation_LIBS
-  NAMES ${DDSegmentation_LIBRARIES}
-  PATHS ${DDSegmentation_LIBRARY_DIR}
-)
+## Find the DDSegmentation libraries
+#find_library(DDSegmentation_LIBS
+#  NAMES ${DDSegmentation_LIBRARIES}
+#  PATHS ${DDSegmentation_LIBRARY_DIR}
+#)
 
 if(DD4HEP_WITH_GEAR)
-  target_link_libraries(DD4hepRec ${ROOT_LIBRARIES} ${DDSegmentation_LIBS} DD4hepCore Geom Reflex ${libraries} ${GEAR_LIBRARIES} ${GEAR_COMPONENT_LIBRARIES})
+  target_link_libraries(DD4hepRec ${ROOT_LIBRARIES} ${DDSegmentation_LIBRARIES} DD4hepCore Geom Reflex ${libraries} ${GEAR_LIBRARIES} ${GEAR_COMPONENT_LIBRARIES})
 
   #------ binary ----------
   
@@ -45,7 +45,7 @@ if(DD4HEP_WITH_GEAR)
     )
 
 else()
-  target_link_libraries(DD4hepRec ${ROOT_LIBRARIES} ${DDSegmentation_LIBS} DD4hepCore Geom Reflex ${libraries})
+  target_link_libraries(DD4hepRec ${ROOT_LIBRARIES} ${DDSegmentation_LIBRARIES} DD4hepCore Geom Reflex ${libraries})
 endif(DD4HEP_WITH_GEAR)
 
 
diff --git a/ReadMe.txt b/ReadMe.txt
index eba04b033..aa78b9618 100644
--- a/ReadMe.txt
+++ b/ReadMe.txt
@@ -68,7 +68,7 @@ To build and run the simulation examples Geant4 will be required.
   ( minimum is: export ROOTSYS=/data/ilcsoft/root/5.34.03 )
 
 
-- configure and build DDSegmentation
+- optionally configure and build DDSegmentation beforehand
 
   cd DD4hep/DDSegmentation
   mkdir build; cd build
@@ -77,7 +77,7 @@ To build and run the simulation examples Geant4 will be required.
   cd ../../..
   export CMAKE_PREFIX_PATH=`pwd`/DD4hep/DDSegmentation/
 
-- configure and build:
+- configure and build (builds DDSegmentation if not yet done):
 
   cd DD4hep
   mkdir build; cd build
-- 
GitLab