From 2aefa4f8bf39ec8e3c6229b8a3ab0793777ccac5 Mon Sep 17 00:00:00 2001
From: lintao <lintao51@gmail.com>
Date: Tue, 22 Dec 2020 23:10:04 +0800
Subject: [PATCH] WIP: add the install macros.

---
 Analysis/TotalInvMass/CMakeLists.txt |  6 ++++++
 CMakeLists.txt                       | 21 ++++++++++++++++++++
 Detector/CMakeLists.txt              |  2 +-
 Detector/GeomSvc/CMakeLists.txt      | 29 ++++++++++------------------
 4 files changed, 38 insertions(+), 20 deletions(-)

diff --git a/Analysis/TotalInvMass/CMakeLists.txt b/Analysis/TotalInvMass/CMakeLists.txt
index 1f0acbd8..6aaf10b6 100644
--- a/Analysis/TotalInvMass/CMakeLists.txt
+++ b/Analysis/TotalInvMass/CMakeLists.txt
@@ -18,3 +18,9 @@ gaudi_add_module(TotalInvMass
                       EDM4HEP::edm4hep EDM4HEP::edm4hepDict
                       ${ROOT_LIBRARIES}
 )
+
+install(TARGETS TotalInvMass
+  EXPORT CEPCSWTargets
+  RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT bin
+  LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT shlib
+  COMPONENT dev)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 860eaf85..bf890d89 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,6 +6,15 @@ find_package(ROOT COMPONENTS RIO Tree)
 
 find_package(Gaudi)
 
+
+include(GNUInstallDirs)
+include(CTest)
+
+if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
+  set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/InstallArea/ CACHE PATH
+    "Install path prefix, prepended onto install directories." FORCE )
+endif()
+
 # Set up C++ Standard
 # ``-DCMAKE_CXX_STANDARD=<standard>`` when invoking CMake
 set(CMAKE_CXX_STANDARD 17 CACHE STRING "")
@@ -16,3 +25,15 @@ endif()
 
 add_subdirectory(Analysis)
 add_subdirectory(Detector)
+
+##############################################################################
+# INSTALL
+##############################################################################
+
+install(EXPORT ${PROJECT_NAME}Targets
+  NAMESPACE ${PROJECT_NAME}::
+  FILE "${PROJECT_NAME}Targets.cmake"
+  DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/"
+  )
+
+gaudi_install(CMAKE cmake/${PROJECT_NAME}Config.cmake)
diff --git a/Detector/CMakeLists.txt b/Detector/CMakeLists.txt
index 54c2d545..3e8c3f6e 100644
--- a/Detector/CMakeLists.txt
+++ b/Detector/CMakeLists.txt
@@ -5,4 +5,4 @@
 # add_subdirectory(DetEcalMatrix)
 add_subdirectory(DetInterface)
 # add_subdirectory(DetSegmentation)
-# add_subdirectory(GeomSvc)
+add_subdirectory(GeomSvc)
diff --git a/Detector/GeomSvc/CMakeLists.txt b/Detector/GeomSvc/CMakeLists.txt
index 58c69f7e..a4b10c8b 100644
--- a/Detector/GeomSvc/CMakeLists.txt
+++ b/Detector/GeomSvc/CMakeLists.txt
@@ -4,31 +4,22 @@
 #    Desc: implement the IGeomSvc interface.
 ##############################################################################
 
-gaudi_subdir(GeomSvc v0r0)
-
-gaudi_depends_on_subdirs(
-    k4FWCore
-    Detector/DetInterface
-)
-
 find_package(ROOT COMPONENTS MathCore GenVector Geom Tree)
 find_package(DD4hep COMPONENTS DDG4 DDRec REQUIRED)
 find_package(GEAR REQUIRED)
 
-message("GEAR_LIBRARIES: ${GEAR_LIBRARIES}")
-
 gaudi_add_module(GeomSvc
-                 src/GeomSvc.cpp
-                 INCLUDE_DIRS
-                   # DetInterface
-                   # DD4hep
-                   # GaudiKernel
-                   # ROOT 
-                 LINK_LIBRARIES
-                   DD4hep 
+                 SOURCES src/GeomSvc.cpp
+                 LINK
+                   DetInterface
                    ${DD4hep_COMPONENT_LIBRARIES} 
-                   GaudiKernel
+                   Gaudi::GaudiKernel
                    ${GEAR_LIBRARIES}
                    ${ROOT_LIBRARIES}
-                   # ROOT
 )
+
+install(TARGETS GeomSvc
+  EXPORT CEPCSWTargets
+  RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT bin
+  LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT shlib
+  COMPONENT dev)
-- 
GitLab