Back to home page

EIC code displayed by LXR

 
 

    


Warning, /jana2/CMakeLists.txt is written in an unsupported language. File is not indexed.

0001 cmake_minimum_required(VERSION 3.16)
0002 cmake_policy(SET CMP0074 NEW) # find_package() uses <PackageName>_ROOT implicit hints
0003 
0004 project(jana2 VERSION 2.3.3)
0005 
0006 set(CMAKE_POSITION_INDEPENDENT_CODE ON)   # Enable -fPIC for all targets
0007 
0008 # Default the C++ standard to C++17, and validate that they provided one we can use
0009 set(CMAKE_CXX_STANDARD 17 CACHE STRING "Set the C++ standard to be used")
0010 if(NOT CMAKE_CXX_STANDARD MATCHES "14|17|20|23")
0011     message(FATAL_ERROR "Unsupported C++ standard: ${CMAKE_CXX_STANDARD}")
0012 endif()
0013 
0014 string(APPEND CMAKE_CXX_FLAGS_DEBUG " -O0 -g -Wall -Wextra")
0015 
0016 # Expose custom cmake modules
0017 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
0018 
0019 # Require the user to specify CMAKE_INSTALL_PREFIX directly. DO NOT AUTOMATICALLY INSTALL to /usr/local!
0020 # Remember that we ultimately want CMAKE_INSTALL_PREFIX=$ENV{JANA_HOME}
0021 if(NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
0022     message(STATUS "Installing to ${CMAKE_INSTALL_PREFIX} .")
0023 elseif(DEFINED ENV{JANA_HOME})
0024     message(STATUS "Installing to $ENV{JANA_HOME} ..")
0025     set(CMAKE_INSTALL_PREFIX $ENV{JANA_HOME} CACHE PATH "Comment explaining this nonsense" FORCE)
0026 else()
0027     message(STATUS "Missing CMAKE_INSTALL_PREFIX=$JANA_HOME => Defaulting to ${CMAKE_BINARY_DIR}/install")
0028     set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "Comment explaining this nonsense" FORCE)
0029 endif()
0030 
0031 
0032 # Add library directories to rpath so users don't need to use LD_LIBRARY_PATH.
0033 # (see https://dev.my-gate.net/2021/08/04/understanding-rpath-with-cmake )
0034 # TODO: detector MacOS and set MACOSX_RPATH to TRUE
0035 set( CMAKE_SKIP_BUILD_RPATH FALSE )
0036 set( CMAKE_BUILD_WITH_INSTALL_RPATH FALSE )
0037 set( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/lib/JANA/plugins" )
0038 set( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )
0039 
0040 # Generate a compilation database, e.g. for IDE autocompletion
0041 set( CMAKE_EXPORT_COMPILE_COMMANDS TRUE )
0042 
0043 # Useful for debugging. Copied from:
0044 # https://stackoverflow.com/questions/9298278/cmake-print-out-all-accessible-variables-in-a-script
0045 function(dump_cmake_variables)
0046     get_cmake_property(_variableNames VARIABLES)
0047     list (SORT _variableNames)
0048     foreach (_variableName ${_variableNames})
0049         if (ARGV0)
0050             unset(MATCHED)
0051             string(REGEX MATCH ${ARGV0} MATCHED ${_variableName})
0052             if (NOT MATCHED)
0053                 continue()
0054             endif()
0055         endif()
0056         message(STATUS "${_variableName}=${${_variableName}}")
0057     endforeach()
0058 endfunction()
0059 
0060 
0061 #----------------------
0062 # Library dependencies
0063 #----------------------
0064 
0065 option(USE_ROOT "Include ROOT dependency." OFF)
0066 option(USE_ZEROMQ "Include ZeroMQ dependency. (Needed for examples/StreamingExample, plugins/streamDet, plugins/janacontrol), " OFF)
0067 option(USE_XERCES "Include XercesC 3 dependency. (Needed for JGeometryXML)" OFF)
0068 option(USE_PYTHON "Include Python dependency. This requires python-devel and python-distutils." OFF)
0069 option(USE_ASAN "Compile with address sanitizer" OFF)
0070 option(USE_TSAN "Compile with thread sanitizer" OFF)
0071 option(USE_CUDA "Compile CUDA-involved examples (Needed for examples/SubeventCUDAExample)." OFF)
0072 option(USE_PODIO "Compile with PODIO support" OFF)
0073 option(BUILD_SHARED_LIBS "Build into both shared and static libs." ON)
0074 
0075 if (${USE_PODIO})
0076     find_package(podio REQUIRED)
0077     set(JANA2_HAVE_PODIO 1)
0078     set(USE_ROOT ON)
0079     include_directories(SYSTEM ${podio_INCLUDE_DIR})
0080 else()
0081     set(JANA2_HAVE_PODIO 0)
0082 endif()
0083 
0084 
0085 if (${USE_ROOT})
0086     if((NOT DEFINED ROOT_DIR) AND (DEFINED ENV{ROOTSYS}))
0087         set(ROOT_DIR $ENV{ROOTSYS}/cmake)
0088     endif()
0089     find_package(ROOT REQUIRED)
0090     set(JANA2_HAVE_ROOT 1)
0091     include_directories(${ROOT_INCLUDE_DIRS})
0092     link_libraries(${ROOT_LIBRARIES})
0093     execute_process(
0094         COMMAND ${ROOT_BINDIR}/root-config --features
0095         OUTPUT_VARIABLE ROOT_FEATURES
0096     )
0097     if(NOT ${ROOT_FEATURES} MATCHES .*cxx${CMAKE_CXX_STANDARD}.*)
0098         message(STATUS "root-config --features: ${ROOT_FEATURES}.")
0099         message(FATAL_ERROR "ROOT was not compiled against C++${CMAKE_CXX_STANDARD}. "
0100             "Specify the C++ standard used to compile ROOT with e.g. -DCMAKE_CXX_STANDARD=17. "
0101             "Check the root-config output above for cxx flags.")
0102     endif()
0103 else()
0104     set(JANA2_HAVE_ROOT 0)
0105 endif()
0106 
0107 if (${USE_ZEROMQ})
0108     find_package(ZeroMQ REQUIRED)
0109 endif()
0110 
0111 if (${USE_XERCES})
0112     if((NOT DEFINED XercesC_DIR) AND (DEFINED ENV{XERCESCROOT}))
0113         set(XercesC_DIR $ENV{XERCESCROOT})
0114     endif()
0115     find_package(XercesC REQUIRED)
0116     set(JANA2_HAVE_XERCES 1)
0117     include_directories(${XercesC_INCLUDE_DIRS})
0118     link_libraries(${XercesC_LIBRARIES})
0119 else()
0120     set(JANA2_HAVE_XERCES 0)
0121 endif()
0122 
0123 if (${USE_ASAN})
0124     add_compile_options(-fsanitize=address)
0125     add_link_options(-fsanitize=address)
0126 endif()
0127 
0128 if (${USE_TSAN})
0129     add_compile_options(-fsanitize=thread)
0130     add_link_options(-fsanitize=thread)
0131 endif()
0132 
0133 if (${USE_CUDA})
0134     find_package(CUDA REQUIRED)
0135 endif()
0136 
0137 
0138 #---------
0139 # Report back to the user what we've discovered
0140 #---------
0141 
0142 message(STATUS "-----------------------")
0143 message(STATUS "Build type is ${CMAKE_BUILD_TYPE}")
0144 message(STATUS "C++ standard is ${CMAKE_CXX_STANDARD}")
0145 message(STATUS "Installation directory is ${CMAKE_INSTALL_PREFIX}")
0146 if (${USE_ROOT})
0147     message(STATUS "USE_ROOT    On  --> " ${ROOT_DIR})
0148 else()
0149     message(STATUS "USE_ROOT    Off")
0150 endif()
0151 if (${USE_ZEROMQ})
0152     message(STATUS "USE_ZEROMQ  On  --> " ${ZeroMQ_DIR})
0153 else()
0154     message(STATUS "USE_ZEROMQ  Off")
0155 endif()
0156 if (${USE_XERCES})
0157     message(STATUS "USE_XERCES  On  --> " ${XercesC_DIR})
0158 else()
0159     message(STATUS "USE_XERCES  Off")
0160 endif()
0161 if (${USE_PYTHON})
0162     message(STATUS "USE_PYTHON  On")
0163 else()
0164     message(STATUS "USE_PYTHON  Off")
0165 endif()
0166 if (${USE_ASAN})
0167     message(STATUS "USE_ASAN    On")
0168 else()
0169     message(STATUS "USE_ASAN    Off")
0170 endif()
0171 if (${USE_TSAN})
0172     message(STATUS "USE_TSAN    On")
0173 else()
0174     message(STATUS "USE_TSAN    Off")
0175 endif()
0176 if (${USE_CUDA})
0177     message(STATUS "USE_CUDA    On")
0178 else()
0179     message(STATUS "USE_CUDA    Off")
0180 endif()
0181 if (${USE_PODIO})
0182     message(STATUS "USE_PODIO   On  --> " ${podio_DIR})
0183 else()
0184     message(STATUS "USE_PODIO   Off")
0185 endif()
0186 if (${BUILD_SHARED_LIBS})
0187     message(STATUS "BUILD_SHARED_LIBS    On")
0188 else()
0189     message(STATUS "BUILD_SHARED_LIBS    Off")
0190 endif()
0191 message(STATUS "-----------------------")
0192 
0193 #---------
0194 # Targets
0195 #---------
0196 
0197 include_directories(src/libraries)   # So that everyone can find the JANA header files
0198 include_directories(${CMAKE_CURRENT_BINARY_DIR}/src/libraries)   # So that everyone can find JVersion.h
0199 
0200 # This is needed on macos to allow plugins to link without resolving all JANA symbols until runtime
0201 if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
0202     add_link_options(-undefined dynamic_lookup)
0203 endif()
0204 
0205 include(CTest)
0206 include(cmake/AddJanaPlugin.cmake)
0207 include(cmake/AddJanaTest.cmake)
0208 
0209 add_subdirectory(src/external)
0210 add_subdirectory(src/libraries/JANA)
0211 add_subdirectory(src/examples)
0212 add_subdirectory(src/plugins)
0213 add_subdirectory(src/programs/jana)
0214 add_subdirectory(src/programs/unit_tests)
0215 add_subdirectory(src/programs/perf_tests)
0216 add_subdirectory(src/python)
0217 
0218 #---------------------------------------------------------------------------------------
0219 
0220 install(DIRECTORY scripts/ DESTINATION bin FILES_MATCHING PATTERN "jana-*.py"
0221         PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE)
0222 
0223     install(FILES "scripts/jana-status.sh" RENAME "jana-status" DESTINATION "bin"
0224         PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE)
0225 
0226 include(${CMAKE_SOURCE_DIR}/cmake/MakeConfig.cmake)
0227 include(${CMAKE_SOURCE_DIR}/cmake/MakeJanaThis.cmake)
0228 include(${CMAKE_SOURCE_DIR}/cmake/MakeJVersionH.cmake)