Back to home page

EIC code displayed by LXR

 
 

    


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

0001 # Common macro to add plugins
0002 macro(plugin_add _name)
0003 
0004     project(${_name}_project)
0005 
0006     # Check if build with library
0007     foreach(arg IN ITEMS ${ARGN})
0008         if(${arg} STREQUAL "WITH_STATIC_LIBRARY")
0009             set(${_name}_WITH_STATIC_LIB ON)
0010         endif()
0011         if(${arg} STREQUAL "WITH_STATIC_LIB")       # alternative
0012             set(${_name}_WITH_STATIC_LIB ON)
0013         endif()
0014     endforeach()
0015 
0016     # Include JANA by default
0017     find_package(JANA REQUIRED)
0018 
0019     # include logging by default
0020     find_package(spdlog REQUIRED)
0021     find_package(fmt REQUIRED)
0022     set(fmt_INCLUDE_DIR ${fmt_DIR}/../../../include)
0023 
0024     # include ROOT by default
0025     find_package(ROOT REQUIRED)
0026 
0027     # Define plugin
0028     add_library(${_name}_plugin SHARED ${PLUGIN_SOURCES})
0029     target_include_directories(${_name}_plugin PUBLIC ${CMAKE_SOURCE_DIR}/src)
0030     target_include_directories(${_name}_plugin SYSTEM PUBLIC ${JANA_INCLUDE_DIR} )
0031     target_include_directories(${_name}_plugin SYSTEM PUBLIC ${ROOT_INCLUDE_DIRS} )
0032     target_include_directories(${_name}_plugin SYSTEM PUBLIC ${fmt_INCLUDE_DIR} )
0033     set_target_properties(${_name}_plugin PROPERTIES PREFIX "" OUTPUT_NAME "${_name}" SUFFIX ".so")
0034     target_link_libraries(${_name}_plugin ${JANA_LIB} spdlog::spdlog)
0035 
0036     # Install plugin
0037     install(TARGETS ${_name}_plugin DESTINATION ${PLUGIN_OUTPUT_DIRECTORY})
0038 
0039 
0040     if(${_name}_WITH_STATIC_LIB)
0041         # Define library
0042         add_library(${_name}_library STATIC "")
0043             target_include_directories(${_name}_library PUBLIC ${CMAKE_SOURCE_DIR}/src)
0044         target_include_directories(${_name}_library SYSTEM PUBLIC ${JANA_INCLUDE_DIR} )
0045         target_include_directories(${_name}_library SYSTEM PUBLIC ${fmt_INCLUDE_DIR} )
0046         set_target_properties(${_name}_library PROPERTIES PREFIX "lib" OUTPUT_NAME "${_name}" SUFFIX ".a")
0047         target_link_libraries(${_name}_library ${JANA_LIB} spdlog::spdlog)
0048 
0049         # Install plugin
0050         install(TARGETS ${_name}_library DESTINATION ${PLUGIN_LIBRARY_OUTPUT_DIRECTORY})
0051     endif()     # WITH_STATIC_LIB
0052 endmacro()
0053 
0054 
0055 # target_link_libraries for both a plugin and a library
0056 macro(plugin_link_libraries _name)
0057 
0058     #foreach(arg IN ITEMS ${ARGN})
0059     #    target_link_libraries(${_name}_plugin ${arg})
0060     target_link_libraries(${_name}_plugin ${ARGN})
0061     #endforeach()
0062 
0063 
0064 
0065     if(${_name}_WITH_STATIC_LIB)
0066         target_link_libraries(${_name}_library ${ARGN})
0067     endif()     # WITH_STATIC_LIB
0068 endmacro()
0069 
0070 
0071 # target_include_directories for both a plugin and a library
0072 macro(plugin_include_directories _name)
0073     target_include_directories(${_name}_plugin  ${ARGN})
0074 
0075     if(${_name}_WITH_STATIC_LIB)
0076         target_include_directories(${_name}_library ${ARGN})
0077     endif()     # WITH_STATIC_LIB
0078 endmacro()
0079 
0080 
0081 # runs target_sources both for library and a plugin
0082 macro(plugin_sources _name)
0083     # This is needed as this is a macro (see cmake macro documentation)
0084     set(SOURCES ${ARGN})
0085 
0086     # Add sources to plugin
0087     target_sources(${_name}_plugin PRIVATE ${SOURCES})
0088 
0089     if(${_name}_WITH_STATIC_LIB)
0090         # Library don't need <plugin_name>.cc in library
0091         set(PLUGIN_CC_FILE ${_name}.cc)
0092         get_filename_component(PLUGIN_CC_FILE "${CMAKE_CURRENT_LIST_DIR}/${PLUGIN_CC_FILE}" ABSOLUTE)
0093         list(REMOVE_ITEM SOURCES ${PLUGIN_CC_FILE})
0094 
0095         # Add sources to library
0096         target_sources(${_name}_library PRIVATE ${SOURCES})
0097     endif()     # WITH_STATIC_LIB
0098 endmacro()
0099 
0100 # The macro grabs sources as *.cc *.cpp *.c and headers as *.h *.hh *.hpp
0101 # Then correctly sets sources for ${_name}_plugin and ${_name}_library targets
0102 # Adds headers to the correct installation directory
0103 macro(plugin_glob_all _name)
0104 
0105     # But... GLOB here makes this file just hot pluggable
0106     file(GLOB LIB_SRC_FILES *.cc *.cpp *.c)
0107     file(GLOB PLUGIN_SRC_FILES *.cc *.cpp *.c)
0108     file(GLOB HEADER_FILES *.h *.hh *.hpp)
0109 
0110     # We need plugin relative path for correct headers installation
0111     string(REPLACE ${CMAKE_SOURCE_DIR}/src "" PLUGIN_RELATIVE_PATH ${PROJECT_SOURCE_DIR})
0112 
0113     # Add sources to plugin
0114     target_sources(${_name}_plugin PRIVATE ${PLUGIN_SRC_FILES})
0115 
0116     #Add correct headers installation
0117     # Install headers for plugin
0118     install(FILES ${HEADER_FILES} DESTINATION include/${PLUGIN_RELATIVE_PATH})
0119 
0120     if(${_name}_WITH_STATIC_LIB)
0121         # Library don't need <plugin_name>.cc but Plugin does
0122         set(PLUGIN_CC_FILE ${_name}.cc)
0123 
0124         # Make the path absolute as GLOB files will be absolute paths
0125         get_filename_component(PLUGIN_CC_FILE_ABS "${CMAKE_CURRENT_LIST_DIR}/${PLUGIN_CC_FILE}" ABSOLUTE)
0126 
0127         # Remove plugin.cc file from libraries
0128         list(REMOVE_ITEM LIB_SRC_FILES ${PLUGIN_CC_FILE_ABS})
0129 
0130         # >oO Debug output if needed
0131         if(${EICRECON_VERBOSE_CMAKE})
0132             message(STATUS "plugin_glob_all:${_name}: LIB_SRC_FILES    ${LIB_SRC_FILES}")
0133         endif()
0134 
0135         # Finally add sources to library
0136         target_sources(${_name}_library PRIVATE ${LIB_SRC_FILES})
0137     endif()     # WITH_STATIC_LIB
0138 
0139     # >oO Debug output if needed
0140     if(${EICRECON_VERBOSE_CMAKE})
0141         message(STATUS "plugin_glob_all:${_name}: PLUGIN_CC_FILE   ${PLUGIN_CC_FILE}")
0142         message(STATUS "plugin_glob_all:${_name}: LIB_SRC_FILES    ${LIB_SRC_FILES}")
0143         message(STATUS "plugin_glob_all:${_name}: PLUGIN_SRC_FILES ${PLUGIN_SRC_FILES}")
0144         message(STATUS "plugin_glob_all:${_name}: HEADER_FILES     ${HEADER_FILES}")
0145         message(STATUS "plugin_glob_all:${_name}: PLUGIN_RLTV_PATH ${PLUGIN_RELATIVE_PATH}")
0146     endif()
0147 
0148     # To somehow control GLOB lets at least PRINT files we are going to compile:
0149     message(STATUS "Source files:")
0150     print_file_names("  " ${PLUGIN_SRC_FILES})    # Prints source files
0151     message(STATUS "Plugin-main file is: ${PLUGIN_CC_FILE}")
0152     message(STATUS "Header files:")
0153     print_file_names("  " ${HEADER_FILES})  # Prints header files
0154 
0155 endmacro()