From a3091a5f159ef796cdda197018bb0ce646d87bf9 Mon Sep 17 00:00:00 2001
From: Florian Uhlig <f.uhlig@gsi.de>
Date: Tue, 7 Dec 2021 17:15:34 +0100
Subject: [PATCH] Fix linking of externals

Add patch needed to for NicaFemto which adds missing library dependencies.

Add missing link directory and library dependency for fles logging library.

Use Vc from FairSoft if available
Only build the internal Vc version if none is found in FairSoft installation.
This solves the problem with failing macros due to incosistent versions
of Vc library and header files.
---
 external/CMakeLists.txt          | 13 ++++++++++++-
 external/InstallKFParticle.cmake |  2 +-
 external/NicaFemto.patch         | 26 ++++++++++++++++++++++++++
 external/ipc/CMakeLists.txt      |  4 ++++
 4 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt
index 6b19bb8d0e..1768203c4d 100644
--- a/external/CMakeLists.txt
+++ b/external/CMakeLists.txt
@@ -23,7 +23,18 @@ if(DOWNLOAD_EXTERNALS)
   Add_Subdirectory(ipc)
   Add_Subdirectory(flib_dpb)
 
-  Include(InstallVC.cmake)
+  find_package(Vc 1.4.1)
+  if(NOT Vc_FOUND)
+    Message("Vc not found in FairSoft installation, Build included version.")
+    Include(InstallVC.cmake)
+    set(KF_DEPENDS_ON "Vc")
+  else()
+    # Missing from VcConfig.cmake
+    set(VC_INCLUDE_DIRS ${Vc_INCLUDE_DIR} PARENT_SCOPE)
+    set(Vc_LIB_DIR ${Vc_ROOTDIR}/${_LIBDIR_DEFAULT} PARENT_SCOPE)
+    set(KF_DEPENDS_ON "")
+  endif()
+
   Include(InstallKFParticle.cmake)
   Include(InstallNicaFemto.cmake)
   Include(InstallAnalysisTree.cmake)
diff --git a/external/InstallKFParticle.cmake b/external/InstallKFParticle.cmake
index a63895adba..9077654497 100644
--- a/external/InstallKFParticle.cmake
+++ b/external/InstallKFParticle.cmake
@@ -17,7 +17,7 @@ If(ProjectUpdated)
 EndIf()
 
 ExternalProject_Add(KFPARTICLE
-  DEPENDS Vc
+  DEPENDS ${KF_DEPENDS_ON}
   BUILD_IN_SOURCE 0
   SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/KFParticle
   BUILD_BYPRODUCTS ${KFPARTICLE_LIBRARY}
diff --git a/external/NicaFemto.patch b/external/NicaFemto.patch
index 9ba0a9d75f..52e1a9ca67 100644
--- a/external/NicaFemto.patch
+++ b/external/NicaFemto.patch
@@ -24,3 +24,29 @@ index 60ab7e6..b70ab36 100644
            endif()
            find_package(GSL REQUIRED)
          endif()
+diff --git a/cuts/CMakeLists.txt b/cuts/CMakeLists.txt
+index 1d1c4f0..e5676ba 100755
+--- a/cuts/CMakeLists.txt
++++ b/cuts/CMakeLists.txt
+@@ -114,7 +114,7 @@ cutmonitors/NicaPropertyMonitorXYZ.cxx
+ Set(HEADERS )
+ Set(LINKDEF NicaCutLinkDef.h)
+ Set(LIBRARY_NAME NicaCut)
+-Set(DEPENDENCIES NicaFeatures)
++Set(DEPENDENCIES NicaFeatures NicaDataFormat Base)
+ 
+ GENERATE_LIBRARY()
+ 
+diff --git a/dataformat/CMakeLists.txt b/dataformat/CMakeLists.txt
+index b8576ab..b3fc335 100644
+--- a/dataformat/CMakeLists.txt
++++ b/dataformat/CMakeLists.txt
+@@ -57,7 +57,7 @@ hiddeninfo/NicaV0Track.cxx
+ Set(HEADERS )
+ Set(LINKDEF NicaDataFormatLinkDef.h)
+ Set(LIBRARY_NAME NicaDataFormat)
+-Set(DEPENDENCIES NicaFeatures ${NICAFORMATLIBS})
++Set(DEPENDENCIES NicaFeatures ${NICAFORMATLIBS} Base EG)
+ 
+ GENERATE_LIBRARY()
+ 
diff --git a/external/ipc/CMakeLists.txt b/external/ipc/CMakeLists.txt
index b85c7934a9..569ee95668 100644
--- a/external/ipc/CMakeLists.txt
+++ b/external/ipc/CMakeLists.txt
@@ -24,6 +24,10 @@ target_include_directories(fles_logging PUBLIC ipc/lib/logging/)
 
 target_include_directories(fles_logging SYSTEM PUBLIC ${Boost_INCLUDE_DIRS})
 
+target_link_directories(fles_logging PUBLIC ${Boost_LIBRARY_DIRS})
+
+target_link_libraries(fles_logging boost_log)
+
 Install(TARGETS fles_logging DESTINATION lib)
 
 Set(INCLUDE_DIRECTORIES
-- 
GitLab