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.4.2)
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 for all targets
0033 set( CMAKE_SKIP_BUILD_RPATH FALSE )
0034 set( CMAKE_BUILD_WITH_INSTALL_RPATH FALSE )
0035 set( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;${CMAKE_INSTALL_PREFIX}/lib/JANA/plugins" )
0036 set( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )
0037
0038 # Generate a compilation database, e.g. for IDE autocompletion
0039 set( CMAKE_EXPORT_COMPILE_COMMANDS TRUE )
0040
0041 # Useful for debugging. Copied from:
0042 # https://stackoverflow.com/questions/9298278/cmake-print-out-all-accessible-variables-in-a-script
0043 function(dump_cmake_variables)
0044 get_cmake_property(_variableNames VARIABLES)
0045 list (SORT _variableNames)
0046 foreach (_variableName ${_variableNames})
0047 if (ARGV0)
0048 unset(MATCHED)
0049 string(REGEX MATCH ${ARGV0} MATCHED ${_variableName})
0050 if (NOT MATCHED)
0051 continue()
0052 endif()
0053 endif()
0054 message(STATUS "${_variableName}=${${_variableName}}")
0055 endforeach()
0056 endfunction()
0057
0058
0059 #----------------------
0060 # Library dependencies
0061 #----------------------
0062
0063 option(USE_ROOT "Include ROOT dependency." OFF)
0064 option(USE_ZEROMQ "Include ZeroMQ dependency. (Needed for examples/StreamingExample, plugins/streamDet, plugins/janacontrol), " OFF)
0065 option(USE_XERCES "Include XercesC 3 dependency. (Needed for JGeometryXML)" OFF)
0066 option(USE_PYTHON "Include Python dependency. This requires python-devel and python-distutils." OFF)
0067 option(USE_ASAN "Compile with address sanitizer" OFF)
0068 option(USE_TSAN "Compile with thread sanitizer" OFF)
0069 option(USE_CUDA "Compile CUDA-involved examples (Needed for examples/SubeventCUDAExample)." OFF)
0070 option(USE_PODIO "Compile with PODIO support" OFF)
0071 option(BUILD_SHARED_LIBS "Build into both shared and static libs." ON)
0072
0073 if (${USE_PODIO})
0074 find_package(podio REQUIRED)
0075 set(JANA2_HAVE_PODIO 1)
0076 set(USE_ROOT ON)
0077 include_directories(SYSTEM ${podio_INCLUDE_DIR})
0078 else()
0079 set(JANA2_HAVE_PODIO 0)
0080 endif()
0081
0082
0083 if (${USE_ROOT})
0084 if((NOT DEFINED ROOT_DIR) AND (DEFINED ENV{ROOTSYS}))
0085 set(ROOT_DIR $ENV{ROOTSYS}/cmake)
0086 endif()
0087 find_package(ROOT REQUIRED)
0088 set(JANA2_HAVE_ROOT 1)
0089 include_directories(${ROOT_INCLUDE_DIRS})
0090 link_libraries(${ROOT_LIBRARIES})
0091 execute_process(
0092 COMMAND ${ROOT_BINDIR}/root-config --features
0093 OUTPUT_VARIABLE ROOT_FEATURES
0094 )
0095 if(NOT ${ROOT_FEATURES} MATCHES .*cxx${CMAKE_CXX_STANDARD}.*)
0096 message(STATUS "root-config --features: ${ROOT_FEATURES}.")
0097 message(FATAL_ERROR "ROOT was not compiled against C++${CMAKE_CXX_STANDARD}. "
0098 "Specify the C++ standard used to compile ROOT with e.g. -DCMAKE_CXX_STANDARD=17. "
0099 "Check the root-config output above for cxx flags.")
0100 endif()
0101 else()
0102 set(JANA2_HAVE_ROOT 0)
0103 endif()
0104
0105 if (${USE_ZEROMQ})
0106 find_package(ZeroMQ REQUIRED)
0107 endif()
0108
0109 if (${USE_XERCES})
0110 if((NOT DEFINED XercesC_DIR) AND (DEFINED ENV{XERCESCROOT}))
0111 set(XercesC_DIR $ENV{XERCESCROOT})
0112 endif()
0113 find_package(XercesC REQUIRED)
0114 set(JANA2_HAVE_XERCES 1)
0115 include_directories(${XercesC_INCLUDE_DIRS})
0116 link_libraries(${XercesC_LIBRARIES})
0117 else()
0118 set(JANA2_HAVE_XERCES 0)
0119 endif()
0120
0121 if (${USE_ASAN})
0122 add_compile_options(-fsanitize=address)
0123 add_link_options(-fsanitize=address)
0124 endif()
0125
0126 if (${USE_TSAN})
0127 add_compile_options(-fsanitize=thread)
0128 add_link_options(-fsanitize=thread)
0129 endif()
0130
0131 if (${USE_CUDA})
0132 find_package(CUDA REQUIRED)
0133 endif()
0134
0135
0136 #---------
0137 # Report back to the user what we've discovered
0138 #---------
0139
0140 message(STATUS "-----------------------")
0141 message(STATUS "Build type is ${CMAKE_BUILD_TYPE}")
0142 message(STATUS "C++ standard is ${CMAKE_CXX_STANDARD}")
0143 message(STATUS "Installation directory is ${CMAKE_INSTALL_PREFIX}")
0144 if (${USE_ROOT})
0145 message(STATUS "USE_ROOT On --> " ${ROOT_DIR})
0146 else()
0147 message(STATUS "USE_ROOT Off")
0148 endif()
0149 if (${USE_ZEROMQ})
0150 message(STATUS "USE_ZEROMQ On --> " ${ZeroMQ_DIR})
0151 else()
0152 message(STATUS "USE_ZEROMQ Off")
0153 endif()
0154 if (${USE_XERCES})
0155 message(STATUS "USE_XERCES On --> " ${XercesC_DIR})
0156 else()
0157 message(STATUS "USE_XERCES Off")
0158 endif()
0159 if (${USE_PYTHON})
0160 message(STATUS "USE_PYTHON On")
0161 else()
0162 message(STATUS "USE_PYTHON Off")
0163 endif()
0164 if (${USE_ASAN})
0165 message(STATUS "USE_ASAN On")
0166 else()
0167 message(STATUS "USE_ASAN Off")
0168 endif()
0169 if (${USE_TSAN})
0170 message(STATUS "USE_TSAN On")
0171 else()
0172 message(STATUS "USE_TSAN Off")
0173 endif()
0174 if (${USE_CUDA})
0175 message(STATUS "USE_CUDA On")
0176 else()
0177 message(STATUS "USE_CUDA Off")
0178 endif()
0179 if (${USE_PODIO})
0180 message(STATUS "USE_PODIO On --> " ${podio_DIR})
0181 else()
0182 message(STATUS "USE_PODIO Off")
0183 endif()
0184 if (${BUILD_SHARED_LIBS})
0185 message(STATUS "BUILD_SHARED_LIBS On")
0186 else()
0187 message(STATUS "BUILD_SHARED_LIBS Off")
0188 endif()
0189 message(STATUS "-----------------------")
0190
0191 #---------
0192 # Targets
0193 #---------
0194
0195 include_directories(src/libraries) # So that everyone can find the JANA header files
0196 include_directories(${CMAKE_CURRENT_BINARY_DIR}/src/libraries) # So that everyone can find JVersion.h
0197
0198 # This is needed on macos to allow plugins to link without resolving all JANA symbols until runtime
0199 if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
0200 add_link_options(-undefined dynamic_lookup)
0201 endif()
0202
0203 include(CTest)
0204 include(cmake/AddJanaPlugin.cmake)
0205 include(cmake/AddJanaTest.cmake)
0206
0207 add_subdirectory(src/external)
0208 add_subdirectory(src/libraries/JANA)
0209 add_subdirectory(src/examples)
0210 add_subdirectory(src/plugins)
0211 add_subdirectory(src/programs/jana)
0212 add_subdirectory(src/programs/unit_tests)
0213 add_subdirectory(src/programs/perf_tests)
0214 add_subdirectory(src/python)
0215
0216 #---------------------------------------------------------------------------------------
0217
0218 install(DIRECTORY scripts/ DESTINATION bin FILES_MATCHING PATTERN "jana-*.py"
0219 PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE)
0220
0221 install(FILES "scripts/jana-status.sh" RENAME "jana-status" DESTINATION "bin"
0222 PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE)
0223
0224 include(${CMAKE_SOURCE_DIR}/cmake/MakeConfig.cmake)
0225 include(${CMAKE_SOURCE_DIR}/cmake/MakeJanaThis.cmake)
0226 include(${CMAKE_SOURCE_DIR}/cmake/MakeJVersionH.cmake)