From b972d5f56248591b7fa17b23f60ba60eb6270ddb Mon Sep 17 00:00:00 2001
From: oafedulidis <oafedulidis@ep1.rub.de>
Date: Tue, 16 Jan 2024 17:08:57 +0100
Subject: [PATCH] redirecting cmake find_package to ROOTSYS path

---
 CMakeLists.txt                | 10 ++++------
 FitParams/CMakeLists.txt      |  4 ++--
 KMatrixExtract/CMakeLists.txt |  2 +-
 MinFunctions/CMakeLists.txt   |  2 +-
 PwaDynamics/CMakeLists.txt    |  2 +-
 ggUtils/CMakeLists.txt        |  2 +-
 gslUtils/CMakeLists.txt       |  2 +-
 7 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 476c9785..30262941 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,19 +5,17 @@ set(CXX_STANDARD 17)
 set(CXX_STANDARD_REQUIRED ON)
 
 if(DEFINED ENV{ROOTSYS})  
-  set(ROOT_INCLUDE_DIRS "$ENV{ROOTSYS}/include")
-  set(ROOT_LIBRARIES "$ENV{ROOTSYS}/lib")
-  MESSAGE(STATUS "found env var ROOTSYS")
-  MESSAGE(STATUS "root include path is: ${ROOT_INCLUDE_DIRS}")
-  MESSAGE(STATUS "root lib path is: ${ROOT_LIBRARIES}")
+  MESSAGE(STATUS "ROOTSYS is defined, trying to find package in this directory")
+  find_package(ROOT PATHS $ENV{ROOTSYS} NO_DEFAULT_PATH)
+  MESSAGE(STATUS "${ROOT_INCLUDE_DIRS}")
 else()
   MESSAGE(STATUS "ROOTSYS not defined using find_package(ROOT)")
   find_package(ROOT)
+  MESSAGE(STATUS "${ROOT_INCLUDE_DIRS}")
 endif()
 
 find_package(Boost)
 find_package(Boost COMPONENTS program_options unit_test_framework serialization filesystem timer REQUIRED)
-
 find_package(GSL REQUIRED)
 
 #include_directories(
diff --git a/FitParams/CMakeLists.txt b/FitParams/CMakeLists.txt
index 97b03d68..7a797937 100644
--- a/FitParams/CMakeLists.txt
+++ b/FitParams/CMakeLists.txt
@@ -15,7 +15,7 @@ target_include_directories(FitParams
 )
 
 target_link_libraries(FitParams  
-  ${ROOT_LIBRARIES}/libMinuit2.so
+  ROOT::Minuit2
 )
 
 install(TARGETS FitParams
@@ -38,7 +38,7 @@ target_link_libraries(StreamerTestApp
   ConfigParser
   qft++Extension
   ErrLogger
-  ${ROOT_LIBRARIES}/libMinuit2.so
+  ROOT::Minuit2
 )
 
 add_executable(PwaCovMatrixApp
diff --git a/KMatrixExtract/CMakeLists.txt b/KMatrixExtract/CMakeLists.txt
index 5f6198e3..85585f6c 100644
--- a/KMatrixExtract/CMakeLists.txt
+++ b/KMatrixExtract/CMakeLists.txt
@@ -16,7 +16,7 @@ target_include_directories(KMatrixExtract
 )
 
 target_link_libraries(KMatrixExtract    
-  ${ROOT_LIBRARIES}/libMinuit2.so 
+  ROOT::Minuit2
 )
 
 install(TARGETS KMatrixExtract
diff --git a/MinFunctions/CMakeLists.txt b/MinFunctions/CMakeLists.txt
index f3361de9..0f8eeee3 100644
--- a/MinFunctions/CMakeLists.txt
+++ b/MinFunctions/CMakeLists.txt
@@ -25,7 +25,7 @@ target_link_libraries(MinFunctions
   PwaDynamics
   PspGen
   PwaUtils
-  ${ROOT_LIBRARIES}/libMinuit2.so
+  ROOT::Minuit2
   ${Boost_LIBRARIES}
 )
 
diff --git a/PwaDynamics/CMakeLists.txt b/PwaDynamics/CMakeLists.txt
index 18a06db3..6156927d 100644
--- a/PwaDynamics/CMakeLists.txt
+++ b/PwaDynamics/CMakeLists.txt
@@ -20,7 +20,7 @@ target_link_libraries(PwaDynamics
   qft++
   qft++Extension
   ErrLogger
-  ${ROOT_LIBRARIES}/libMinuit2.so
+  ROOT::Minuit2
 )
 
 install(TARGETS PwaDynamics
diff --git a/ggUtils/CMakeLists.txt b/ggUtils/CMakeLists.txt
index c6c7efd8..358f59af 100644
--- a/ggUtils/CMakeLists.txt
+++ b/ggUtils/CMakeLists.txt
@@ -16,7 +16,7 @@ target_include_directories(ggUtils
 )
 
 target_link_libraries(ggUtils
-  ${ROOT_LIBRARIES}/libMinuit2.so
+  ROOT::Minuit2
 )
 
 install(TARGETS ggUtils
diff --git a/gslUtils/CMakeLists.txt b/gslUtils/CMakeLists.txt
index 0495bd87..ea99d478 100644
--- a/gslUtils/CMakeLists.txt
+++ b/gslUtils/CMakeLists.txt
@@ -22,7 +22,7 @@ target_link_libraries(gslUtils
   qft++
   qft++Extension
   ErrLogger
-  ${ROOT_LIBRARIES}/libMinuit2.so
+  ROOT::Minuit2
   GSL::gsl
   GSL::gslcblas
 )
-- 
GitLab