From 8f5ff6393b91b1b8915cb6e03a70d73da71d0bf8 Mon Sep 17 00:00:00 2001
From: Christian Grefe <Christian.Grefe@cern.ch>
Date: Tue, 15 Jul 2014 11:15:45 +0000
Subject: [PATCH] Made DDSegmentation stand-alone

---
 CMakeLists.txt                                |  4 ++-
 DDSegmentation/CMakeLists.txt                 | 29 ++++++++++++++++--
 .../cmake/DDSegmentationConfig.cmake.in       | 30 +++++++++++++++++++
 3 files changed, 60 insertions(+), 3 deletions(-)
 create mode 100644 DDSegmentation/cmake/DDSegmentationConfig.cmake.in

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 368fa1959..454c2242b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -66,8 +66,10 @@ IF( INSTALL_DOC )
 ENDIF()
 
 
+find_package(DDSegmentation REQUIRED)
+
 #---Packages------------------------------------------------------------------------
-add_subdirectory(DDSegmentation)
+#add_subdirectory(DDSegmentation)
 add_subdirectory(DDCore)
 add_subdirectory(DDSurfaces)
 add_subdirectory(DDRec)
diff --git a/DDSegmentation/CMakeLists.txt b/DDSegmentation/CMakeLists.txt
index a35084a9c..75a438142 100644
--- a/DDSegmentation/CMakeLists.txt
+++ b/DDSegmentation/CMakeLists.txt
@@ -1,4 +1,20 @@
 cmake_minimum_required(VERSION 2.8.3 FATAL_ERROR)
+project(DDSegmentation)
+ 
+set(DDSegmentation_MAJOR_VERSION 0)
+set(DDSegmentation_MINOR_VERSION 1)
+set(DDSegmentation_PATCH_VERSION 0)
+set(DDSegmentation_VERSION ${DDSegmentation_MAJOR_VERSION}.${DDSegmentation_MINOR_VERSION}.${DDSegmentation_PATCH_VERSION})
+set(DDSegmentation_SOVERSION "${DDSegmentation_MAJOR_VERSION}.${DDSegmentation_MINOR_VERSION}.${DDSegmentation_PATCH_VERSION}" )
+
+#------------- set the default installation directory to be the source directory
+
+IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
+  SET( CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR} CACHE PATH  
+    "install prefix path  - overwrite with -D CMAKE_INSTALL_PREFIX = ..." 
+    FORCE )
+  MESSAGE(STATUS "CMAKE_INSTALL_PREFIX is ${CMAKE_INSTALL_PREFIX} - overwrite with -D CMAKE_INSTALL_PREFIX" )
+ENDIF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
 
 include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/include )
 
@@ -6,7 +22,7 @@ file(GLOB sources src/*.cpp)
 
 add_library(DDSegmentation SHARED ${sources})
 
-SET_TARGET_PROPERTIES( DDSegmentation PROPERTIES VERSION ${DD4hep_VERSION} SOVERSION ${DD4hep_SOVERSION})
+SET_TARGET_PROPERTIES( DDSegmentation PROPERTIES VERSION ${DDSegmentation_VERSION} SOVERSION ${DDSegmentation_SOVERSION})
 
 install(DIRECTORY include/DDSegmentation
   DESTINATION include
@@ -17,4 +33,13 @@ install(TARGETS DDSegmentation
   LIBRARY DESTINATION lib
   )
 # to do: add corresponding uninstall...
-#-------------------------------------------------------
\ No newline at end of file
+#-------------------------------------------------------
+
+# Export the package for use from the build-tree
+# (this registers the build-tree with a global CMake-registry)
+export(PACKAGE DDSegmentation)
+ 
+# Create the DDSegmentationConfig.cmake and DDSegmentationConfigVersion files
+configure_file(cmake/DDSegmentationConfig.cmake.in ${CMAKE_INSTALL_PREFIX}/DDSegmentationConfig.cmake)
+
+#install(FILES ${PROJECT_SOURCE_DIR}/DDSegmentationConfig.cmake DESTINATION . )
diff --git a/DDSegmentation/cmake/DDSegmentationConfig.cmake.in b/DDSegmentation/cmake/DDSegmentationConfig.cmake.in
new file mode 100644
index 000000000..2d74d16cb
--- /dev/null
+++ b/DDSegmentation/cmake/DDSegmentationConfig.cmake.in
@@ -0,0 +1,30 @@
+##############################################################################
+# cmake configuration file for DDSegmentation
+#
+# returns following variables:
+#
+#   DDSegmentation_FOUND      : set to TRUE if DDSegmentation found
+#   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_LIBRARY_DIR  : list of paths to be used with LINK_DIRECTORIES
+#
+# @author Christian Grefe, CERN
+##############################################################################
+
+SET( DDSegmentation_ROOT "@CMAKE_INSTALL_PREFIX@" )
+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 )
+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 )
+
+SET( DDSegmentation_FOUND ${DDSegmentation_FOUND} )
-- 
GitLab