Back to home page

EIC code displayed by LXR

 
 

    


Warning, /EICrecon/cmake/jana_plugin.cmake is written in an unsupported language. File is not indexed.

0001 # Ensure GNU filesystem layout
0002 include(GNUInstallDirs)
0003 
0004 # Sets up properties common for plugin "library" library or "plugin" library
0005 macro(_plugin_common_target_properties _target)
0006   target_include_directories(
0007     ${_target}
0008     PUBLIC $<BUILD_INTERFACE:${EICRECON_SOURCE_DIR}/src>
0009            $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>)
0010   target_include_directories(${_target} SYSTEM PUBLIC ${JANA_INCLUDE_DIR})
0011   target_link_libraries(
0012     ${_target}
0013     ${JANA_LIB}
0014     podio::podio
0015     podio::podioRootIO
0016     spdlog::spdlog
0017     fmt::fmt
0018     Microsoft.GSL::GSL)
0019 
0020   target_compile_definitions(
0021     ${_target}
0022     PRIVATE "JANA_VERSION_MAJOR=${JANA_VERSION_MAJOR}"
0023             "JANA_VERSION_MINOR=${JANA_VERSION_MINOR}"
0024             "JANA_VERSION_PATCH=${JANA_VERSION_PATCH}")
0025 
0026   # Ensure datamodel headers are available
0027   if(TARGET podio_datamodel_glue)
0028     add_dependencies(${_target} podio_datamodel_glue)
0029   endif()
0030 endmacro()
0031 
0032 # Common macro to add plugins
0033 macro(plugin_add _name)
0034 
0035   # Default to plugin without library
0036   set(${_name}_WITH_LIBRARY OFF)
0037   set(${_name}_WITH_PLUGIN ON)
0038 
0039   # Check if build with library
0040   foreach(arg IN ITEMS ${ARGN})
0041     if(${arg} STREQUAL "WITH_STATIC_LIBRARY")
0042       set(${_name}_WITH_LIBRARY ON)
0043       set(${_name}_LIBRARY_TYPE STATIC)
0044     endif()
0045     if(${arg} STREQUAL "WITH_SHARED_LIBRARY")
0046       set(${_name}_WITH_LIBRARY ON)
0047       set(${_name}_LIBRARY_TYPE SHARED)
0048     endif()
0049     if(${arg} STREQUAL "WITHOUT_PLUGIN")
0050       set(${_name}_WITH_PLUGIN OFF)
0051     endif()
0052   endforeach()
0053 
0054   # Define plugin
0055   if(${_name}_WITH_PLUGIN)
0056     add_library(${_name}_plugin SHARED)
0057 
0058     _plugin_common_target_properties(${_name}_plugin)
0059 
0060     set_target_properties(
0061       ${_name}_plugin
0062       PROPERTIES PREFIX ""
0063                  OUTPUT_NAME "${_name}"
0064                  SUFFIX ".so")
0065 
0066     # Install plugin
0067     install(
0068       TARGETS ${_name}_plugin
0069       EXPORT EICreconTargets
0070       DESTINATION ${PLUGIN_OUTPUT_DIRECTORY})
0071   endif(${_name}_WITH_PLUGIN)
0072 
0073   # Define library
0074   if(${_name}_WITH_LIBRARY)
0075     add_library(${_name}_library ${${_name}_LIBRARY_TYPE} "")
0076 
0077     _plugin_common_target_properties(${_name}_library)
0078 
0079     if(${_name}_LIBRARY_TYPE STREQUAL "STATIC")
0080       set(suffix ".a")
0081     endif()
0082     if(${_name}_LIBRARY_TYPE STREQUAL "SHARED")
0083       set(suffix ".so")
0084     endif()
0085     set_target_properties(
0086       ${_name}_library
0087       PROPERTIES PREFIX "lib"
0088                  OUTPUT_NAME "${_name}"
0089                  SUFFIX ${suffix})
0090 
0091     # Install library
0092     install(
0093       TARGETS ${_name}_library
0094       EXPORT EICreconTargets
0095       DESTINATION ${PLUGIN_LIBRARY_OUTPUT_DIRECTORY})
0096   endif(${_name}_WITH_LIBRARY)
0097 
0098   if(${_name}_WITH_LIBRARY AND ${_name}_WITH_PLUGIN)
0099     # Ensure that whenever a plugin is loaded its library is loaded as well
0100     if(CXX_LINKER_HAS_no_as_needed)
0101       target_link_libraries(${_name}_plugin
0102                             $<LINK_LIBRARY:NO_AS_NEEDED,${_name}_library>)
0103     else()
0104       target_link_libraries(${_name}_plugin ${_name}_library)
0105     endif()
0106   endif()
0107 endmacro()
0108 
0109 # add_dependencies for both a plugin and a library
0110 macro(plugin_add_dependencies _name)
0111   if(${_name}_WITH_PLUGIN)
0112     add_dependencies(${_name}_plugin ${ARGN})
0113   endif(${_name}_WITH_PLUGIN)
0114 
0115   if(${_name}_WITH_LIBRARY)
0116     add_dependencies(${_name}_library ${ARGN})
0117   endif(${_name}_WITH_LIBRARY)
0118 endmacro()
0119 
0120 # target_link_libraries for both a plugin and a library
0121 macro(plugin_link_libraries _name)
0122   if(${_name}_WITH_PLUGIN)
0123     target_link_libraries(${_name}_plugin ${ARGN})
0124   endif(${_name}_WITH_PLUGIN)
0125 
0126   if(${_name}_WITH_LIBRARY)
0127     target_link_libraries(${_name}_library ${ARGN})
0128   endif(${_name}_WITH_LIBRARY)
0129 endmacro()
0130 
0131 # target_include_directories for both a plugin and a library
0132 macro(plugin_include_directories _name)
0133   if(${_name}_WITH_PLUGIN)
0134     target_include_directories(${_name}_plugin ${ARGN})
0135   endif(${_name}_WITH_PLUGIN)
0136 
0137   if(${_name}_WITH_LIBRARY)
0138     target_include_directories(${_name}_library ${ARGN})
0139   endif(${_name}_WITH_LIBRARY)
0140 endmacro()
0141 
0142 # runs target_sources both for library and a plugin
0143 macro(plugin_sources _name)
0144   # This is needed as this is a macro (see cmake macro documentation)
0145   set(SOURCES ${ARGN})
0146 
0147   # Add sources to plugin
0148   target_sources(${_name}_plugin PRIVATE ${SOURCES})
0149 
0150   if(${_name}_WITH_LIBRARY)
0151     # Library don't need <plugin_name>.cc in library
0152     set(PLUGIN_CC_FILE ${_name}.cc)
0153     get_filename_component(
0154       PLUGIN_CC_FILE "${CMAKE_CURRENT_LIST_DIR}/${PLUGIN_CC_FILE}" ABSOLUTE)
0155     list(REMOVE_ITEM SOURCES ${PLUGIN_CC_FILE})
0156 
0157     # Add sources to library
0158     target_sources(${_name}_library PRIVATE ${SOURCES})
0159   endif(${_name}_WITH_LIBRARY)
0160 endmacro()
0161 
0162 # installs headers in current directory
0163 macro(plugin_headers_only _name)
0164   # get all headers
0165   file(GLOB HEADER_FILES CONFIGURE_DEPENDS *.h *.hh *.hpp)
0166 
0167   # We need plugin relative path for correct headers installation (FIXME cmake
0168   # 3.20: cmake_path)
0169   file(RELATIVE_PATH PLUGIN_RELATIVE_PATH ${PROJECT_SOURCE_DIR}/src
0170        ${CMAKE_CURRENT_SOURCE_DIR})
0171 
0172   # FIXME cmake 3.23: define FILE_SET on target_sources
0173   install(
0174     FILES ${HEADER_FILES}
0175     DESTINATION
0176       ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${PLUGIN_RELATIVE_PATH})
0177 endmacro()
0178 
0179 # The macro grabs sources as *.cc *.cpp *.c and headers as *.h *.hh *.hpp Then
0180 # correctly sets sources for ${_name}_plugin and ${_name}_library targets Adds
0181 # headers to the correct installation directory
0182 macro(plugin_glob_all _name)
0183 
0184   # But... GLOB here makes this file just hot pluggable
0185   file(GLOB LIB_SRC_FILES CONFIGURE_DEPENDS *.cc *.cpp *.c)
0186   if(${_name}_WITH_LIBRARY)
0187     file(GLOB PLUGIN_SRC_FILES CONFIGURE_DEPENDS ${_name}.cc)
0188   else()
0189     file(GLOB PLUGIN_SRC_FILES CONFIGURE_DEPENDS *.cc *.cpp *.c)
0190   endif()
0191   file(GLOB HEADER_FILES CONFIGURE_DEPENDS *.h *.hh *.hpp)
0192 
0193   # We need plugin relative path for correct headers installation (FIXME cmake
0194   # 3.20: cmake_path)
0195   file(RELATIVE_PATH PLUGIN_RELATIVE_PATH ${PROJECT_SOURCE_DIR}/src
0196        ${CMAKE_CURRENT_SOURCE_DIR})
0197 
0198   # Add sources to plugin
0199   if(TARGET ${_name}_plugin)
0200     target_sources(${_name}_plugin PRIVATE ${PLUGIN_SRC_FILES})
0201   endif()
0202 
0203   # FIXME cmake 3.23: define FILE_SET on target_sources
0204   install(
0205     FILES ${HEADER_FILES}
0206     DESTINATION
0207       ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${PLUGIN_RELATIVE_PATH})
0208 
0209   if(${_name}_WITH_LIBRARY)
0210     # Library don't need <plugin_name>.cc but Plugin does
0211     set(PLUGIN_CC_FILE ${_name}.cc)
0212 
0213     # Make the path absolute as GLOB files will be absolute paths
0214     get_filename_component(
0215       PLUGIN_CC_FILE_ABS "${CMAKE_CURRENT_LIST_DIR}/${PLUGIN_CC_FILE}" ABSOLUTE)
0216 
0217     # Remove plugin.cc file from libraries
0218     list(REMOVE_ITEM LIB_SRC_FILES ${PLUGIN_CC_FILE_ABS})
0219 
0220     # Finally add sources to library
0221     target_sources(${_name}_library PRIVATE ${LIB_SRC_FILES})
0222 
0223     # Debug output if needed
0224     message(VERBOSE
0225             "plugin_glob_all:${_name}: PLUGIN_CC_FILE   ${PLUGIN_CC_FILE}")
0226   endif(${_name}_WITH_LIBRARY)
0227 
0228   # Debug output if needed
0229   message(VERBOSE "plugin_glob_all:${_name}: LIB_SRC_FILES    ${LIB_SRC_FILES}")
0230   message(VERBOSE
0231           "plugin_glob_all:${_name}: PLUGIN_SRC_FILES ${PLUGIN_SRC_FILES}")
0232   message(VERBOSE "plugin_glob_all:${_name}: HEADER_FILES     ${HEADER_FILES}")
0233   message(VERBOSE
0234           "plugin_glob_all:${_name}: PLUGIN_RLTV_PATH ${PLUGIN_RELATIVE_PATH}")
0235 
0236 endmacro()
0237 
0238 # Adds algorithms for a plugin
0239 macro(plugin_add_algorithms _name)
0240 
0241   if(NOT algorithms_FOUND)
0242     find_package(algorithms ${algorithms_VERSION_MIN} REQUIRED)
0243   endif()
0244 
0245   if(${_name}_WITH_LIBRARY)
0246     target_compile_definitions(
0247       ${PLUGIN_NAME}_library
0248       PRIVATE "algorithms_VERSION_MAJOR=${algorithms_VERSION_MAJOR}"
0249               "algorithms_VERSION_MINOR=${algorithms_VERSION_MINOR}")
0250   endif()
0251   if(${_name}_WITH_PLUGIN)
0252     target_compile_definitions(
0253       ${PLUGIN_NAME}_plugin
0254       PRIVATE "algorithms_VERSION_MAJOR=${algorithms_VERSION_MAJOR}"
0255               "algorithms_VERSION_MINOR=${algorithms_VERSION_MINOR}")
0256   endif()
0257 
0258   plugin_link_libraries(${_name} algorithms::algocore)
0259 
0260 endmacro()
0261 
0262 # Adds dd4hep for a plugin
0263 macro(plugin_add_dd4hep _name)
0264 
0265   if(NOT DD4hep_FOUND)
0266     find_package(DD4hep ${DD4hep_VERSION_MIN} REQUIRED)
0267   endif()
0268 
0269   plugin_link_libraries(${_name} DD4hep::DDCore DD4hep::DDRec)
0270 
0271 endmacro()
0272 
0273 # Adds Eigen3 for a plugin
0274 macro(plugin_add_eigen3 _name)
0275 
0276   if(NOT Eigen3_FOUND)
0277     find_package(Eigen3 ${Eigen3_VERSION_MIN} REQUIRED)
0278   endif()
0279 
0280   plugin_link_libraries(${_name} Eigen3::Eigen)
0281 
0282 endmacro()
0283 
0284 # Adds ACTS tracking package for a plugin
0285 macro(plugin_add_acts _name)
0286 
0287   if(NOT Acts_FOUND)
0288     find_package(Acts REQUIRED COMPONENTS Core PluginDD4hep PluginJson)
0289     set(Acts_VERSION
0290         "${Acts_VERSION_MAJOR}.${Acts_VERSION_MINOR}.${Acts_VERSION_PATCH}")
0291     if(${Acts_VERSION} VERSION_LESS ${Acts_VERSION_MIN})
0292       message(
0293         FATAL_ERROR
0294           "Acts version ${Acts_VERSION_MIN} or higher required, but ${Acts_VERSION} found"
0295       )
0296     endif()
0297   endif()
0298 
0299   if(${Acts_VERSION} VERSION_GREATER_EQUAL "43.0.0")
0300     set(Acts_NAMESPACE_PREFIX Acts::)
0301   else()
0302     set(Acts_NAMESPACE_PREFIX Acts)
0303   endif()
0304 
0305   # Get ActsExamples base
0306   get_target_property(ActsCore_LOCATION ${Acts_NAMESPACE_PREFIX}Core LOCATION)
0307   get_filename_component(ActsCore_PATH ${ActsCore_LOCATION} DIRECTORY)
0308 
0309   # Add libraries (works same as target_include_directories)
0310   plugin_link_libraries(
0311     ${PLUGIN_NAME}
0312     ${Acts_NAMESPACE_PREFIX}Core
0313     ${Acts_NAMESPACE_PREFIX}PluginDD4hep
0314     ${Acts_NAMESPACE_PREFIX}PluginJson
0315     ${ActsCore_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}ActsExamplesFramework${CMAKE_SHARED_LIBRARY_SUFFIX}
0316   )
0317   if(${_name}_WITH_LIBRARY)
0318     target_compile_definitions(
0319       ${PLUGIN_NAME}_library PRIVATE "Acts_VERSION_MAJOR=${Acts_VERSION_MAJOR}"
0320                                      "Acts_VERSION_MINOR=${Acts_VERSION_MINOR}")
0321   endif()
0322   if(${_name}_WITH_PLUGIN)
0323     target_compile_definitions(
0324       ${PLUGIN_NAME}_plugin PRIVATE "Acts_VERSION_MAJOR=${Acts_VERSION_MAJOR}"
0325                                     "Acts_VERSION_MINOR=${Acts_VERSION_MINOR}")
0326   endif()
0327 
0328 endmacro()
0329 
0330 # Adds IRT PID reconstruction package for a plugin
0331 macro(plugin_add_irt _name)
0332 
0333   if(NOT IRT_FOUND)
0334     find_package(IRT ${IRT_VERSION_MIN} REQUIRED)
0335   endif()
0336 
0337   # FIXME: IRTConfig.cmake sets INTERFACE_INCLUDE_DIRECTORIES to
0338   # <prefix>/include/IRT instead of <prefix>/include, allowing for short-form
0339   # #include <CherenkovDetector.h>
0340   get_target_property(IRT_INTERFACE_INCLUDE_DIRECTORIES IRT
0341                       INTERFACE_INCLUDE_DIRECTORIES)
0342   list(TRANSFORM IRT_INTERFACE_INCLUDE_DIRECTORIES REPLACE "/IRT$" "")
0343   list(REMOVE_DUPLICATES IRT_INTERFACE_INCLUDE_DIRECTORIES)
0344   set_target_properties(IRT PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
0345                                        "${IRT_INTERFACE_INCLUDE_DIRECTORIES}")
0346 
0347   plugin_link_libraries(${PLUGIN_NAME} IRT)
0348 
0349 endmacro()
0350 
0351 # Adds podio, edm4hep, edm4eic for a plugin
0352 macro(plugin_add_event_model _name)
0353 
0354   if(NOT podio_FOUND)
0355     find_package(podio ${podio_VERSION_MIN} QUIET)
0356     if(NOT podio_FOUND)
0357       find_package(podio 1.0 REQUIRED)
0358     endif()
0359   endif()
0360 
0361   if(NOT EDM4HEP_FOUND)
0362     find_package(EDM4HEP ${EDM4HEP_VERSION_MIN} REQUIRED)
0363   endif()
0364 
0365   if(NOT EDM4EIC_FOUND)
0366     find_package(EDM4EIC ${EDM4EIC_VERSION_MIN} REQUIRED)
0367   endif()
0368 
0369   # Add include directories
0370   plugin_include_directories(
0371     ${PLUGIN_NAME} PUBLIC $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
0372     $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>)
0373 
0374   # Add libraries (same as target_include_directories but for both plugin and
0375   # library)
0376   plugin_link_libraries(${PLUGIN_NAME} podio::podio EDM4EIC::edm4eic
0377                         EDM4HEP::edm4hep)
0378 
0379 endmacro()
0380 
0381 # Adds cern ROOT for a plugin
0382 macro(plugin_add_cern_root _name)
0383 
0384   if(NOT ROOT_FOUND)
0385     find_package(ROOT ${ROOT_VERSION_MIN} REQUIRED)
0386   endif()
0387 
0388   # Add libraries
0389   plugin_link_libraries(${PLUGIN_NAME} ROOT::Core ROOT::EG)
0390 
0391 endmacro()
0392 
0393 # Adds FastJet for a plugin
0394 macro(plugin_add_fastjet _name)
0395 
0396   if(NOT FASTJET_FOUND)
0397     find_package(FastJet ${FastJet_VERSION_MIN} REQUIRED)
0398   endif()
0399 
0400   # Add include directories
0401   plugin_include_directories(${PLUGIN_NAME} SYSTEM PUBLIC
0402                              ${FASTJET_INCLUDE_DIRS})
0403 
0404   # Add libraries
0405   plugin_link_libraries(${PLUGIN_NAME} ${FASTJET_LIBRARIES})
0406 
0407 endmacro()
0408 
0409 # Adds FastJetTools for a plugin
0410 macro(plugin_add_fastjettools _name)
0411 
0412   if(NOT FJTOOLS_FOUND)
0413     find_package(FastJetTools ${FastJet_VERSION_MIN} REQUIRED)
0414   endif()
0415 
0416   # Add include directories
0417   plugin_include_directories(${PLUGIN_NAME} SYSTEM PUBLIC
0418                              ${FJTOOLS_INCLUDE_DIRS})
0419 
0420   # Add libraries
0421   plugin_link_libraries(${PLUGIN_NAME} ${FJTOOLS_LIBRARIES})
0422 
0423 endmacro()
0424 
0425 # Adds FastJetContrib for a plugin
0426 macro(plugin_add_fastjetcontrib _name)
0427 
0428   if(NOT FJCONTRIB_FOUND)
0429     find_package(FastJetContrib ${FastJetContrib_VERSION_MIN} REQUIRED)
0430   endif()
0431 
0432   # Add include directories
0433   plugin_include_directories(${PLUGIN_NAME} SYSTEM PUBLIC
0434                              ${FJCONTRIB_INCLUDE_DIRS})
0435 
0436   # Add libraries
0437   plugin_link_libraries(${PLUGIN_NAME} ${FJCONTRIB_LIBRARIES})
0438 
0439 endmacro()
0440 
0441 # Adds ONNX Runtime for a plugin
0442 macro(plugin_add_onnxruntime _name)
0443 
0444   if(NOT onnxruntime_FOUND)
0445     find_package(onnxruntime ${onnxruntime_MIN_VERSION} CONFIG)
0446   endif()
0447 
0448   # Add libraries
0449   plugin_link_libraries(${PLUGIN_NAME} onnxruntime::onnxruntime)
0450 
0451 endmacro()