diff --git a/CMakeLists.txt b/CMakeLists.txt index efcc5b6b8e4578448f3cb87a1f1df0f91d8db012..4ece9e6f2354abaffca924fd075bdcce7eed1de0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ if(NOT CMAKE_CXX_STANDARD MATCHES "14|17") message(FATAL_ERROR "Unsupported C++ standard: ${CMAKE_CXX_STANDARD}") endif() +list(PREPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") # (Find*.cmake) include(cmake/CEPCSWDependencies.cmake) add_subdirectory(Analysis) diff --git a/Examples/CMakeLists.txt b/Examples/CMakeLists.txt index 9c00a9eaa78745d8e3ddac59f1377379e7d3db6b..6d37ea639a5354eb09dd50e37a86ce23a596654a 100644 --- a/Examples/CMakeLists.txt +++ b/Examples/CMakeLists.txt @@ -18,6 +18,10 @@ gaudi_add_module(Examples ${podio_LIBRARIES} podio::podioRootIO ) +if (GenFit_FOUND) + target_link_libraries(Examples PUBLIC GenFit::genfit2) +endif() + target_include_directories(Examples PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>/include $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) diff --git a/cmake/CEPCSWDependencies.cmake b/cmake/CEPCSWDependencies.cmake index 92d8911e3e65a9a6f09548c2aec2b73a082e4c61..78aa0f26d7c8c84bfb581cb6bdebf9c53568e522 100644 --- a/cmake/CEPCSWDependencies.cmake +++ b/cmake/CEPCSWDependencies.cmake @@ -31,3 +31,4 @@ find_package(LCIO REQUIRED) find_package(PandoraSDK REQUIRED) find_package(podio REQUIRED) find_package(ROOT COMPONENTS EG Graf Graf3d Gpad MathCore Net RIO Tree TreePlayer REQUIRED) +find_package(GenFit) diff --git a/cmake/FindGenFit.cmake b/cmake/FindGenFit.cmake new file mode 100644 index 0000000000000000000000000000000000000000..6a3cf181bb45f63a5608fb6cc3eb8692fe1ef89b --- /dev/null +++ b/cmake/FindGenFit.cmake @@ -0,0 +1,55 @@ +# - Try to find GenFit +# Defines: +# +# GenFit_FOUND +# GenFit_INCLUDE_DIRS +# GenFit_LIBRARIES +# +# Imports: +# +# GenFit::genfit2 +# +# Usage of the target instead of the variables is advised + +# Find quietly if already found before +if(DEFINED CACHE{GenFit_INCLUDE_DIRS}) + set(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY YES) +endif() + +find_path(GenFit_INCLUDE_DIRS NAMES GFGbl.h + HINTS ${GENFIT_ROOT_DIR}/include $ENV{GENFIT_ROOT_DIR}/include + ${GenFit_DIR}/include $ENV{GenFit_DIR}/include + ${CMAKE_PREFIX_PATH}/include +) +find_library(GenFit_LIBRARIES NAMES genfit2 + HINTS $ENV{GENFIT_ROOT_DIR}/lib ${GENFIT_ROOT_DIR}/lib + ${GenFit_DIR}/lib ${GenFit_DIR}/lib64 + $ENV{GenFit_DIR}/lib $ENV{GenFit_DIR}/lib64 + ${CMAKE_PREFIX_PATH}/lib ${CMAKE_PREFIX_PATH}/lib64 +) + +# handle the QUIETLY and REQUIRED arguments and set GENFIT_FOUND to TRUE if +# all listed variables are TRUE +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GenFit DEFAULT_MSG GenFit_INCLUDE_DIRS GenFit_LIBRARIES) + +mark_as_advanced(GenFit_FOUND GenFit_INCLUDE_DIRS GenFit_LIBRARIES) + +# Modernisation: create an interface target to link against +if(TARGET GenFit::genfit2) + return() +endif() +if(GenFit_FOUND) + add_library(GenFit::genfit2 IMPORTED INTERFACE) + target_include_directories(GenFit::genfit2 SYSTEM INTERFACE "${GenFit_INCLUDE_DIRS}") + target_link_libraries(GenFit::genfit2 INTERFACE "${GenFit_LIBRARIES}") + + # Display the imported target for the user to know + if(NOT ${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY) + message(STATUS " Import target: GenFit::genfit2") + endif() +endif() + +if(COMMAND __deprecate_var_for_target) + variable_watch(GenFit_INCLUDE_DIRS __deprecate_var_for_target) +endif()