Newer
Older
# The name of our project is "CBMROOT". CMakeLists files in this project can
# refer to the root source directory of the project as ${CBMROOT_SOURCE_DIR} or
# as ${CMAKE_SOURCE_DIR} and to the root binary directory of the project as
# ${CBMROOT_BINARY_DIR} or ${CMAKE_BINARY_DIR}.
# Check if cmake has the required version
# Since flesnet requires 3.14.0 we should be consistent while we
# build it in the CbmRoot context
cmake_minimum_required(VERSION 3.14.0 FATAL_ERROR)
cmake_policy(VERSION 3.14...3.23)
# Define compiler on macosx to avoid problems when comparing to compilers
# used for FairSoft/FairRoot compilation
if(APPLE)
if(NOT DEFINED CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER clang)
endif()
if(NOT DEFINED CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER clang++)
endif()
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
# Set the library version in the main CMakeLists.txt
set(CBMROOT_MAJOR_VERSION 22)
set(CBMROOT_MINOR_VERSION 2)
set(CBMROOT_PATCH_VERSION 99)
execute_process(
COMMAND bash "-c" "cd ${CMAKE_SOURCE_DIR} && git log | head -n 1 | sed 's_commit \\(.[^ ]*\\)_\\1_' && cd ${OLDPWD}"
OUTPUT_VARIABLE CBMROOT_BUILD_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND bash "-c" "cd ${CMAKE_SOURCE_DIR} && git log | sed -n '3 s/Date:[ ]*//p' && cd ${OLDPWD}"
OUTPUT_VARIABLE CBMROOT_BUILD_HASH_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE)
message("CBMROOT BUILD HASH is ${CBMROOT_BUILD_HASH} dated on ${CBMROOT_BUILD_HASH_DATE}.")
# Set name of our project to "CBMROOT"
# This also sets ${CBMROOT_VERSION} to the provided VERSION value, which would be empty if not set here explicitly

Pierre-Alain Loizeau
committed
project(CBMROOT
VERSION ${CBMROOT_MAJOR_VERSION}.${CBMROOT_MINOR_VERSION}.${CBMROOT_PATCH_VERSION}
LANGUAGES C CXX
)
# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/
# is checked
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
# Load some basic cmake functionality
include(ExternalProject)
include(CTest)
# Make the CbmRoot cmake functions available
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
include(CbmChecks)
include(CbmGenerateConfig)
include(CbmMacros)
include(CbmTargets)
include(CbmCompilerSettings)
include(FairMacros)
include(WriteConfigFile)
include(CheckCompiler)
# Do some basic checks
# out-of-source build, unix system and
# existence of FAIRROOTPATH and SIMPATH variables
Check_Prerequisites()
#Fairsoft Modules Path
list(PREPEND CMAKE_PREFIX_PATH ${SIMPATH})
#Searches for ROOT Package
find_package(ROOT 6.22 CONFIG REQUIRED)
if(ROOT_FOUND)
endif()
find_package(FairCMakeModules REQUIRED)
include(FairFindPackage2)
#Searches for FairLogger Package
find_package2(PUBLIC FairLogger)
# at the end after all find_package[2] calls, call once
find_package2_implicit_dependencies()
if(FairLogger_FOUND)
set(FAIRLOGGER_INCLUDE_DIR ${FairLogger_INCDIR}/fairlogger)
# CbmRoot expects that the Logger include statement does not need any
# additional path in the statement
# The target FairLogger::FairLogger does not provide the needed info
# So we add the additional subdirectory here to the target
get_target_property(_incDirs FairLogger::FairLogger INTERFACE_INCLUDE_DIRECTORIES)
set_target_properties(FairLogger::FairLogger PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_incDirs}/fairlogger"
)
endif()

Felix Weiglhofer
committed
#Searches for VMC Package
if(ROOT_vmc_FOUND)
set(VMCLIB ROOT::VMC)
else()
find_package2(PUBLIC VMC REQUIRED)
set(VMCLIB VMCLibrary)
endif()
if(VMC_FOUND)
endif()
#Searches for FairROOT Package
list(APPEND packages FairRoot)
set(FairRoot_FOUND TRUE)

Pierre-Alain Loizeau
committed
#Searching for Boost Package
find_package(ZeroMQ)
if(ZeroMQ_FOUND)
list(APPEND packages ZeroMQ)
endif()
find_package(Boost COMPONENTS serialization regex filesystem log log_setup container program_options thread iostreams system)
endif()
#Searching for Geant4 Package
find_package(Geant4 CONFIG REQUIRED)
if(Geant4_FOUND)
#Searching for Vc Package
find_package(Vc 1.4.1 CONFIG REQUIRED)
if(Vc_FOUND)
#Searching for VGM Package
find_package(VGM CONFIG REQUIRED)
if(VGM_FOUND)
endif()
#Searching for Geant4VMC Package
find_package(Geant4VMC CONFIG REQUIRED)
if(Geant4VMC_FOUND)
endif()
#Searching for Geant3 Package
find_package(Geant3 CONFIG REQUIRED)
if(Geant3_FOUND)
endif()
#Searching for SSE
find_package(SSE REQUIRED)
if(SSE_FOUND)
#Searching for format package
find_package(fmt CONFIG REQUIRED)
if(fmt_FOUND)
list(APPEND packages fmt)
endif()
#Searching for FairMQ
find_package(FairMQ CONFIG REQUIRED)
if(FairMQ_FOUND)
get_target_property(_inDirMQ FairMQ::FairMQ INTERFACE_INCLUDE_DIRECTORIES)

Pierre-Alain Loizeau
committed
set_property(TARGET FairMQ::FairMQ APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${_inDirMQ}/fairmq/options")
# Check if the compiler supports the needed C++ standard
# Check for the minimum required versions of FairSoft and FairRoot
check_external_stack()
# Define where the produced targets are placed in the binary directory

Felix Weiglhofer
committed
Set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
Set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin")
Set(INCLUDE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/include")
# VMCWORKDIR is needed by the CbmRoot runtime to find macros, geometries and
# parameters
Set(VMCWORKDIR ${CBMROOT_SOURCE_DIR})
# Set library versioning
set(FAIRROOT_LIBRARY_PROPERTIES ${FAIRROOT_LIBRARY_PROPERTIES}
VERSION "${CBMROOT_VERSION}"
SOVERSION "${CBMROOT_MAJOR_VERSION}"
)

Pierre-Alain Loizeau
committed
# Searching for OpenMP + control variable prep. for config script (default behavior + override)

Pierre-Alain Loizeau
committed
set(OMP_NUM_THREADS 1)
If(DEFINED ENV{OMP_NUM_THREADS} )
set(OMP_NUM_THREADS $ENV{OMP_NUM_THREADS})
endif()
set(CBMLIBDIR ${CMAKE_BINARY_DIR}/lib)
set(LD_LIBRARY_PATH ${CBMLIBDIR} ${Boost_LIBRARY_DIRS} ${LD_LIBRARY_PATH} ${FAIRROOT_LIBRARY_DIR})
set(ROOT_INCLUDE_PATH ${FAIRROOT_INCLUDE_DIR})
# Recurse into the given subdirectories. This does not actually
# cause another cmake executable to run. The same process will walk through
# the project's entire directory structure.
Option(BUILD_UNITTESTS "Build all unit tests and add them as new tests" ON)
If(BUILD_UNITTESTS)
Message("Build the unit tests.")
Message(STATUS "Build internal GTest")
Include(external/InstallGtest.cmake)
### Subdirectories to be compiled #####
### Externals included and build from several sources
# Must be the first subdirectory since the defined targets are needed by
# following targets
add_subdirectory (external)
option(BUILD_FOR_TIDY "Create compile commands database needed by clang-tidy" OFF)
# Add the default compiler include paths needed for our static standalone clang-tidy
# binary. The paths are only added to the compilation units in the generated file
# compile_commands.json which is used as input for clang-tidy. Without the
# paths clang-tidy can't find the standard C and C++ header files.
# Also add special compile options to use the scalar version of VC.
# Otherwise hardware and compiler dependent header files may not be found.
# Since we want to check our code and not some system headers this is
# acceptable.
if(BUILD_FOR_TIDY)
ADD_DEFINITIONS(-DVc_IMPL=Scalar)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES
${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}
)
endif()
### Base directories
add_subdirectory (core)
add_subdirectory (sim)
add_subdirectory (reco)
add_subdirectory (analysis)
add_subdirectory (services)
Option(LARGE_TEST_STATISTIC "Run the test suite with large statistic (100 events)" OFF)
if(NOT CBM_TEST_MODEL)
set(CBM_TEST_MODEL Experimental)
endif()
add_subdirectory (macro)
add_subdirectory(fles)
add_subdirectory(MQ)
EndIf()
add_subdirectory(tutorials)
message(STATUS "*** Building the Doxygen documentaion ***")
add_subdirectory(doxygen)
endif()

Pierre-Alain Loizeau
committed
# Definde additional targets
# cleanlib: rm al Cbm libraries and dictionaries
# cleantest: remove all files from build directory created when running ROOT macros

Pierre-Alain Loizeau
committed
# FormatCheck: execute clang-format for all changed files (needed for CI)

Pierre-Alain Loizeau
committed
# generate the needed config files to run macros from build and
# installation directories. The later will be installed into the
# install directory
generate_config_files()
# install the parameters, geometries and input directories
Install(DIRECTORY geometry input parameters
DESTINATION share/cbmroot
PATTERN ".git" EXCLUDE)

Felix Weiglhofer
committed