From 2fb71e1204c6cabaedeb5e7a4ceb10a52b41dfd0 Mon Sep 17 00:00:00 2001
From: Andre Sailer <andre.philippe.sailer@cern.ch>
Date: Wed, 16 Jul 2014 15:22:19 +0000
Subject: [PATCH] Changes in DDSegmentation CMakeLists

Rename DDSegmentation_INCLUDE_DIR to ..._DIRS
Fix standalone build of DDSegmentation, set DDSegmentation_LIBRARIES in DDSegmentationConfig.cmake
Keep the choice to use external DDSegmentation, set _LIBRARIES and INCLUDE_DIRS in DDSegmentation CMakeLists.txt in case of internal build
---
 CMakeLists.txt                                  | 11 ++++-------
 DDCore/CMakeLists.txt                           | 16 +++++-----------
 DDRec/CMakeLists.txt                            |  8 +-------
 DDSegmentation/CMakeLists.txt                   |  6 ++++++
 .../cmake/DDSegmentationConfig.cmake.in         | 17 +++++++++++------
 5 files changed, 27 insertions(+), 31 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 48c55c05c..498eec13b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -66,19 +66,16 @@ IF( INSTALL_DOC )
 ENDIF()
 
 
-#------ allow to use a pre-built DDSegmentation  ----------------------------
 
-find_package(DDSegmentation QUIET)
 
-#if it does not exist, simply build DDSegmentation as part of DD4hep:
+#---Packages------------------------------------------------------------------------
+
+#------ allow to use a pre-built DDSegmentation  ----------------------------
+find_package( DDSegmentation QUIET )
 if( NOT DDSegmentation_FOUND ) 
   add_subdirectory(DDSegmentation)
-  SET( DDSegmentation_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/DDSegmentation/include)
-  SET( DDSegmentation_LIBRARIES DDSegmentation)
 endif()
 
-#---Packages------------------------------------------------------------------------
-
 add_subdirectory(DDCore)
 add_subdirectory(DDSurfaces)
 add_subdirectory(DDRec)
diff --git a/DDCore/CMakeLists.txt b/DDCore/CMakeLists.txt
index 459c38812..f1374bcfd 100644
--- a/DDCore/CMakeLists.txt
+++ b/DDCore/CMakeLists.txt
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8.3 FATAL_ERROR)
 
 project(DDCore)
 
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${ROOT_INCLUDE_DIR} ${DDSegmentation_INCLUDE_DIR} )
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${ROOT_INCLUDE_DIR} ${DDSegmentation_INCLUDE_DIRS} )
 
 
 file(GLOB sources src/*.cpp src/Evaluator/*.cpp src/XML/*.cpp)
@@ -13,8 +13,8 @@ if(DD4HEP_USE_BOOST)
   #fg:  canonical way of finding Boost w/ cmake uses 
   #     -D Boost_DIR=_path_to_boost
   #     and then FindBoost.cmake sets the variable Boost_INCLUDE_DIR
-  FIND_PACKAGE( Boost REQUIRED) 
-  include_directories( ${Boost_INCLUDE_DIR})
+  FIND_PACKAGE( Boost REQUIRED ) 
+  include_directories( ${Boost_INCLUDE_DIRS} )
   #list(APPEND include_directories ${BOOST_INCLUDE_DIR})
   file(GLOB parser_sources src/parsers/*.cpp )
   add_definitions(-DDD4HEP_USE_BOOST)
@@ -22,16 +22,10 @@ else()
   file(GLOB parser_sources )
 endif()
 
-## 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)
-list(APPEND headers ${DDSegmentation_INCLUDE_DIR}/DDSegmentation/BitField64.h)
-list(APPEND headers ${DDSegmentation_INCLUDE_DIR}/DDSegmentation/Segmentation.h)
+list(APPEND headers ${DDSegmentation_INCLUDE_DIRS}/DDSegmentation/BitField64.h)
+list(APPEND headers ${DDSegmentation_INCLUDE_DIRS}/DDSegmentation/Segmentation.h)
 list(REMOVE_ITEM headers ${CMAKE_CURRENT_SOURCE_DIR}/include/DD4hep/DetFactoryHelper.h
   ${CMAKE_CURRENT_SOURCE_DIR}/include/DD4hep/Factories.h
   ${CMAKE_CURRENT_SOURCE_DIR}/include/DD4hep/Plugins.h
diff --git a/DDRec/CMakeLists.txt b/DDRec/CMakeLists.txt
index 8800bd0bf..e8dc9e11c 100644
--- a/DDRec/CMakeLists.txt
+++ b/DDRec/CMakeLists.txt
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.0 FATAL_ERROR)
 project(DDRec)
 
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include 
-		    ${DDSegmentation_INCLUDE_DIR}
+		    ${DDSegmentation_INCLUDE_DIRS}
 		    ${ROOT_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/DDSurfaces/include 
 		    ${CMAKE_SOURCE_DIR}/DDCore/include)
 
@@ -26,12 +26,6 @@ endif()
 
 add_library(DD4hepRec SHARED ${sources} )
 
-## 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_LIBRARIES} DD4hepCore Geom Reflex ${libraries} ${GEAR_LIBRARIES} ${GEAR_COMPONENT_LIBRARIES})
 
diff --git a/DDSegmentation/CMakeLists.txt b/DDSegmentation/CMakeLists.txt
index 75a438142..242b2fa30 100644
--- a/DDSegmentation/CMakeLists.txt
+++ b/DDSegmentation/CMakeLists.txt
@@ -24,6 +24,12 @@ add_library(DDSegmentation SHARED ${sources})
 
 SET_TARGET_PROPERTIES( DDSegmentation PROPERTIES VERSION ${DDSegmentation_VERSION} SOVERSION ${DDSegmentation_SOVERSION})
 
+#if DDSegmentation is build as part of dd4hep
+if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) 
+  SET ( DDSegmentation_LIBRARIES DDSegmentation  PARENT_SCOPE )
+  SET ( DDSegmentation_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include  PARENT_SCOPE )
+endif()
+
 install(DIRECTORY include/DDSegmentation
   DESTINATION include
   PATTERN ".svn" EXCLUDE )
diff --git a/DDSegmentation/cmake/DDSegmentationConfig.cmake.in b/DDSegmentation/cmake/DDSegmentationConfig.cmake.in
index 2d74d16cb..dfa7cbc8a 100644
--- a/DDSegmentation/cmake/DDSegmentationConfig.cmake.in
+++ b/DDSegmentation/cmake/DDSegmentationConfig.cmake.in
@@ -7,7 +7,7 @@
 #   DDSegmentation_VERSION    : package version
 #   DDSegmentation_ROOT       : path to this DDSegmentation installation
 #   DDSegmentation_LIBRARIES  : list of DD4hep libraries
-#   DDSegmentation_INCLUDE_DIR  : list of paths to be used with INCLUDE_DIRECTORIES
+#   DDSegmentation_INCLUDE_DIRS  : list of paths to be used with INCLUDE_DIRECTORIES
 #   DDSegmentation_LIBRARY_DIR  : list of paths to be used with LINK_DIRECTORIES
 #
 # @author Christian Grefe, CERN
@@ -18,13 +18,18 @@ SET( DDSegmentation_VERSION "@DDSegmentation_VERSION@" )
 
 # ---------- libraries --------------------------------------------------------
 # do not store find results in cache
-SET( DDSegmentation_INCLUDE_DIR "@CMAKE_INSTALL_PREFIX@/include" )
-SET( DDSegmentation_LIBRARY_DIR "@CMAKE_INSTALL_PREFIX@/lib" )
-SET( DDSegmentation_LIBRARIES DDSegmentation )
+SET( DDSegmentation_INCLUDE_DIRS "@CMAKE_INSTALL_PREFIX@/include" )
+
+
+# Find the DDSegmentation libraries
+find_library(DDSegmentation_LIBRARIES
+  NAMES DDSegmentation
+  PATHS "@CMAKE_INSTALL_PREFIX@/lib"
+)
+
 MARK_AS_ADVANCED( DDSegmentation_INCLUDE_DIRS DDSegmentation_LIBRARY_DIRS DDSegmentation_LIBRARIES )
 
 INCLUDE( FindPackageHandleStandardArgs )
 # set DDSegmentation_FOUND to TRUE if all listed variables are TRUE and not empty
-FIND_PACKAGE_HANDLE_STANDARD_ARGS( DDSegmentation DEFAULT_MSG DDSegmentation_ROOT DDSegmentation_INCLUDE_DIR DDSegmentation_LIBRARIES )
+FIND_PACKAGE_HANDLE_STANDARD_ARGS( DDSegmentation DEFAULT_MSG DDSegmentation_ROOT DDSegmentation_INCLUDE_DIRS DDSegmentation_LIBRARIES )
 
-SET( DDSegmentation_FOUND ${DDSegmentation_FOUND} )
-- 
GitLab