From 7095d98324ecd87839260cfb91c569404e631ecb Mon Sep 17 00:00:00 2001
From: Hadrien Grasland <grasland@lal.in2p3.fr>
Date: Sun, 4 Nov 2018 14:21:12 +0100
Subject: [PATCH] Set the DD4hep path based on the CMake file location

---
 cmake/DD4hepConfig.cmake.in | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/cmake/DD4hepConfig.cmake.in b/cmake/DD4hepConfig.cmake.in
index 40810c557..59da4815b 100644
--- a/cmake/DD4hepConfig.cmake.in
+++ b/cmake/DD4hepConfig.cmake.in
@@ -13,15 +13,23 @@
 # @author Jan Engels, Desy
 ##############################################################################
 
+# Locate the DD4hep install directory. This CMake file is installed in two
+# different locations (root and "cmake" subdir) that we must disambiguate.
+get_filename_component(_thisdir "${CMAKE_CURRENT_LIST_FILE}" PATH)
+get_filename_component(_lastdir "${_thisdir}" NAME)
+if (_lastdir STREQUAL "cmake")
+  get_filename_component(_thisdir "${_thisdir}" PATH)
+endif()
+
 if( DEFINED ENV{DD4hep_DIR} )
   set ( DD4hep_DIR         "$ENV{DD4hep_DIR}" )
 else()
-  set ( DD4hep_DIR         "@CMAKE_INSTALL_PREFIX@" )
+  set ( DD4hep_DIR         "${_thisdir}" )
 endif()
 if( DEFINED ENV{DD4hep_ROOT} )
   set ( DD4hep_ROOT        "$ENV{DD4hep_ROOT}" )
 else()
-  set ( DD4hep_ROOT        "@CMAKE_INSTALL_PREFIX@" )
+  set ( DD4hep_ROOT        "${_thisdir}" )
 endif()
 set ( DD4hep_VERSION     "@DD4hep_VERSION@" )
 set ( DD4hep_SOVERSION   "@DD4hep_SOVERSION@" )
-- 
GitLab