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 2026.03.00)
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 plugins/janacontrol, examples/misc/InteractiveStreamingExample), " 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(USE_PERFETTO "Include Perfetto tracing SDK for performance profiling." OFF)
0072 option(BUILD_SHARED_LIBS "Build into both shared and static libs." ON)
0073 option(BUILD_EXAMPLES "Build and install examples" ON)
0074 option(BUILD_TESTS "Build and install tests" ON)
0075
0076 if (${BUILD_TESTS} AND ${USE_PODIO} AND NOT ${BUILD_EXAMPLES})
0077 message(FATAL_ERROR "BUILD_TESTS=ON requires BUILD_EXAMPLES=ON when USE_PODIO=ON (unit tests depend on the PODIO example datamodel)")
0078 endif()
0079
0080 if (${USE_PODIO})
0081 find_package(podio REQUIRED)
0082 set(JANA2_HAVE_PODIO 1)
0083 set(USE_ROOT ON)
0084 include_directories(SYSTEM ${podio_INCLUDE_DIR})
0085 else()
0086 set(JANA2_HAVE_PODIO 0)
0087 endif()
0088
0089
0090 if (${USE_ROOT})
0091 if((NOT DEFINED ROOT_DIR) AND (DEFINED ENV{ROOTSYS}))
0092 set(ROOT_DIR $ENV{ROOTSYS}/cmake)
0093 endif()
0094 find_package(ROOT REQUIRED)
0095 set(JANA2_HAVE_ROOT 1)
0096 include_directories(${ROOT_INCLUDE_DIRS})
0097 link_libraries(ROOT::Core)
0098 execute_process(
0099 COMMAND ${ROOT_BINDIR}/root-config --features
0100 OUTPUT_VARIABLE ROOT_FEATURES
0101 )
0102 if(NOT ${ROOT_FEATURES} MATCHES .*cxx${CMAKE_CXX_STANDARD}.*)
0103 message(STATUS "root-config --features: ${ROOT_FEATURES}.")
0104 message(FATAL_ERROR "ROOT was not compiled against C++${CMAKE_CXX_STANDARD}. "
0105 "Specify the C++ standard used to compile ROOT with e.g. -DCMAKE_CXX_STANDARD=17. "
0106 "Check the root-config output above for cxx flags.")
0107 endif()
0108 else()
0109 set(JANA2_HAVE_ROOT 0)
0110 endif()
0111
0112 if (${USE_ZEROMQ})
0113 find_package(cppzmq REQUIRED)
0114 endif()
0115
0116 if (${USE_XERCES})
0117 if((NOT DEFINED XercesC_DIR) AND (DEFINED ENV{XERCESCROOT}))
0118 set(XercesC_DIR $ENV{XERCESCROOT})
0119 endif()
0120 find_package(XercesC REQUIRED)
0121 set(JANA2_HAVE_XERCES 1)
0122 include_directories(${XercesC_INCLUDE_DIRS})
0123 link_libraries(${XercesC_LIBRARIES})
0124 else()
0125 set(JANA2_HAVE_XERCES 0)
0126 endif()
0127
0128 if (${USE_ASAN})
0129 add_compile_options(-fsanitize=address)
0130 add_link_options(-fsanitize=address)
0131 endif()
0132
0133 if (${USE_TSAN})
0134 add_compile_options(-fsanitize=thread)
0135 add_link_options(-fsanitize=thread)
0136 endif()
0137
0138 if (${USE_CUDA})
0139 find_package(CUDA REQUIRED)
0140 endif()
0141
0142 if (USE_PERFETTO)
0143 set(PERFETTO_VERSION "55.3" CACHE STRING "Perfetto SDK version to download")
0144 set(PERFETTO_HASH "443b148764c4259c9bf3e724bb508b66f3ff77d30e2ccfafbc0f1791cc08141c" CACHE STRING "Perfetto zip sha256 hash")
0145 set(PERFETTO_SDK_URL "https://github.com/google/perfetto/releases/download/v${PERFETTO_VERSION}/perfetto-cpp-sdk-src.zip")
0146 set(PERFETTO_SDK_ZIP "${CMAKE_BINARY_DIR}/perfetto-cpp-sdk-src-${PERFETTO_VERSION}.zip")
0147 set(PERFETTO_SDK_DIR "${CMAKE_BINARY_DIR}/perfetto_sdk_${PERFETTO_VERSION}")
0148
0149 if(NOT EXISTS "${PERFETTO_SDK_DIR}/perfetto.cc")
0150 message(STATUS "Downloading Perfetto SDK v${PERFETTO_VERSION}...")
0151 file(DOWNLOAD "${PERFETTO_SDK_URL}" "${PERFETTO_SDK_ZIP}"
0152 STATUS DOWNLOAD_STATUS
0153 TLS_VERIFY ON
0154 EXPECTED_HASH SHA256=${PERFETTO_HASH}
0155 )
0156 list(GET DOWNLOAD_STATUS 0 DOWNLOAD_ERROR_CODE)
0157 if(DOWNLOAD_ERROR_CODE)
0158 list(GET DOWNLOAD_STATUS 1 DOWNLOAD_ERROR_MSG)
0159 message(FATAL_ERROR "Failed to download Perfetto SDK from ${PERFETTO_SDK_URL}: ${DOWNLOAD_ERROR_MSG}")
0160 endif()
0161 file(ARCHIVE_EXTRACT INPUT "${PERFETTO_SDK_ZIP}" DESTINATION "${PERFETTO_SDK_DIR}")
0162 endif()
0163
0164 add_library(perfetto_sdk STATIC ${PERFETTO_SDK_DIR}/perfetto.cc)
0165 target_include_directories(perfetto_sdk PUBLIC
0166 $<BUILD_INTERFACE:${PERFETTO_SDK_DIR}>
0167 $<INSTALL_INTERFACE:include/perfetto>
0168 )
0169 target_compile_options(perfetto_sdk PRIVATE
0170 $<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
0171 -Wno-sign-compare -Wno-unused-parameter -Wno-missing-field-initializers>
0172 )
0173 install(TARGETS perfetto_sdk EXPORT jana2_targets DESTINATION lib)
0174 install(FILES ${PERFETTO_SDK_DIR}/perfetto.h DESTINATION include/perfetto)
0175 set(JANA2_HAVE_PERFETTO 1)
0176 else()
0177 set(JANA2_HAVE_PERFETTO 0)
0178 endif()
0179
0180
0181 #---------
0182 # Report back to the user what we've discovered
0183 #---------
0184
0185 message(STATUS "-----------------------")
0186 message(STATUS "Build type is ${CMAKE_BUILD_TYPE}")
0187 message(STATUS "C++ standard is ${CMAKE_CXX_STANDARD}")
0188 message(STATUS "Installation directory is ${CMAKE_INSTALL_PREFIX}")
0189 if (${USE_ROOT})
0190 message(STATUS "USE_ROOT On --> " ${ROOT_DIR})
0191 else()
0192 message(STATUS "USE_ROOT Off")
0193 endif()
0194 if (${USE_ZEROMQ})
0195 message(STATUS "USE_ZEROMQ On --> " ${cppzmq_DIR})
0196 else()
0197 message(STATUS "USE_ZEROMQ Off")
0198 endif()
0199 if (${USE_XERCES})
0200 message(STATUS "USE_XERCES On --> " ${XercesC_DIR})
0201 else()
0202 message(STATUS "USE_XERCES Off")
0203 endif()
0204 if (${USE_PYTHON})
0205 message(STATUS "USE_PYTHON On")
0206 else()
0207 message(STATUS "USE_PYTHON Off")
0208 endif()
0209 if (${USE_ASAN})
0210 message(STATUS "USE_ASAN On")
0211 else()
0212 message(STATUS "USE_ASAN Off")
0213 endif()
0214 if (${USE_TSAN})
0215 message(STATUS "USE_TSAN On")
0216 else()
0217 message(STATUS "USE_TSAN Off")
0218 endif()
0219 if (${USE_CUDA})
0220 message(STATUS "USE_CUDA On")
0221 else()
0222 message(STATUS "USE_CUDA Off")
0223 endif()
0224 if (USE_PERFETTO)
0225 message(STATUS "USE_PERFETTO On")
0226 else()
0227 message(STATUS "USE_PERFETTO Off")
0228 endif()
0229 if (${USE_PODIO})
0230 message(STATUS "USE_PODIO On --> " ${podio_DIR})
0231 else()
0232 message(STATUS "USE_PODIO Off")
0233 endif()
0234 if (${BUILD_SHARED_LIBS})
0235 message(STATUS "BUILD_SHARED_LIBS On")
0236 else()
0237 message(STATUS "BUILD_SHARED_LIBS Off")
0238 endif()
0239 if (${BUILD_EXAMPLES})
0240 message(STATUS "BUILD_EXAMPLES On")
0241 else()
0242 message(STATUS "BUILD_EXAMPLES Off")
0243 endif()
0244 if (${BUILD_TESTS})
0245 message(STATUS "BUILD_TESTS On")
0246 else()
0247 message(STATUS "BUILD_TESTS Off")
0248 endif()
0249 message(STATUS "-----------------------")
0250
0251 #---------
0252 # Targets
0253 #---------
0254
0255 include_directories(src/libraries) # So that everyone can find the JANA header files
0256 include_directories(${CMAKE_CURRENT_BINARY_DIR}/src/libraries) # So that everyone can find JVersion.h
0257
0258 # This is needed on macos to allow plugins to link without resolving all JANA symbols until runtime
0259 if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
0260 add_link_options(-undefined dynamic_lookup)
0261 endif()
0262
0263 include(CTest)
0264 include(cmake/AddJanaPlugin.cmake)
0265 include(cmake/AddJanaLibrary.cmake)
0266 include(cmake/AddJanaTest.cmake)
0267
0268 add_subdirectory(src/external)
0269 add_subdirectory(src/libraries/JANA)
0270 add_subdirectory(src/plugins)
0271 add_subdirectory(src/programs)
0272 add_subdirectory(src/python)
0273
0274 if (${BUILD_EXAMPLES})
0275 add_subdirectory(src/examples)
0276 endif()
0277
0278
0279 #---------------------------------------------------------------------------------------
0280
0281 install(DIRECTORY scripts/ DESTINATION bin FILES_MATCHING PATTERN "jana-*.py"
0282 PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE)
0283
0284 install(FILES "scripts/jana-status.sh" RENAME "jana-status" DESTINATION "bin"
0285 PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE)
0286
0287 include(${CMAKE_SOURCE_DIR}/cmake/MakeConfig.cmake)
0288 include(${CMAKE_SOURCE_DIR}/cmake/MakeJanaThis.cmake)
0289 include(${CMAKE_SOURCE_DIR}/cmake/MakeJVersionH.cmake)