diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b7154f4a73..9ea96fe2d24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,18 +14,20 @@ cmake_minimum_required(VERSION 3.17 FATAL_ERROR) project(O2Physics VERSION 0.0.1 LANGUAGES CXX - DESCRIPTION "Analysis framework for O2") + DESCRIPTION "Physics Analysis for O2") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) set_property(GLOBAL PROPERTY REPORT_UNDEFINED_PROPERTIES) include(GNUInstallDirs) -# Set the default build type to "RelWithDebInfo" -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "RelWithDebInfo" - CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel Coverage." FORCE) -endif(NOT CMAKE_BUILD_TYPE) +cmake_host_system_information(RESULT _totalmem QUERY TOTAL_PHYSICAL_MEMORY) +math(EXPR _total_analysis_jobs "(${_totalmem}-4096)/10240") +if(_total_analysis_jobs LESS_EQUAL 0) + set(_total_analysis_jobs 1) +endif() +set(ANALYSIS_COMPILE_POOL ${_total_analysis_jobs} CACHE STRING "How many parallel analysis compilation jobs") +set_property(GLOBAL PROPERTY JOB_POOLS analysis=${ANALYSIS_COMPILE_POOL}) # C++ standard if(NOT DEFINED CMAKE_CXX_STANDARD) @@ -38,6 +40,12 @@ find_package(O2 CONFIG REQUIRED) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) +include(O2PhysicsDefineOptions) +o2physics_define_options() + +# External dependencies +include(dependencies/CMakeLists.txt) + # Include macros include(O2PhysicsNameTarget) include(O2PhysicsAddExecutable) diff --git a/cmake/O2PhysicsDefineOptions.cmake b/cmake/O2PhysicsDefineOptions.cmake new file mode 100644 index 00000000000..d647fa2fde0 --- /dev/null +++ b/cmake/O2PhysicsDefineOptions.cmake @@ -0,0 +1,21 @@ +# Copyright 2019-2020 CERN and copyright holders of ALICE O2. +# See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +# All rights not expressly granted are reserved. +# +# This software is distributed under the terms of the GNU General Public +# License v3 (GPL Version 3), copied verbatim in the file "COPYING". +# +# In applying this license CERN does not waive the privileges and immunities +# granted to it by virtue of its status as an Intergovernmental Organization +# or submit itself to any jurisdiction. + +include_guard() + +function(o2physics_define_options) + + option(BUILD_SHARED_LIBS "Build shared libs" ON) + + option(ENABLE_CASSERT "Enable asserts" OFF) + + option(ENABLE_UPGRADES "Enable detectors for upgrades" OFF) +endfunction() diff --git a/dependencies/CMakeLists.txt b/dependencies/CMakeLists.txt new file mode 100644 index 00000000000..bf95bfbd59e --- /dev/null +++ b/dependencies/CMakeLists.txt @@ -0,0 +1,12 @@ +# Copyright 2019-2020 CERN and copyright holders of ALICE O2. +# See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +# All rights not expressly granted are reserved. +# +# This software is distributed under the terms of the GNU General Public +# License v3 (GPL Version 3), copied verbatim in the file "COPYING". +# +# In applying this license CERN does not waive the privileges and immunities +# granted to it by virtue of its status as an Intergovernmental Organization +# or submit itself to any jurisdiction. + +include("${CMAKE_CURRENT_LIST_DIR}/O2PhysicsCompileFlags.cmake") diff --git a/dependencies/O2PhysicsCompileFlags.cmake b/dependencies/O2PhysicsCompileFlags.cmake new file mode 100644 index 00000000000..f0a91656b20 --- /dev/null +++ b/dependencies/O2PhysicsCompileFlags.cmake @@ -0,0 +1,56 @@ +# Copyright 2019-2020 CERN and copyright holders of ALICE O2. +# See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +# All rights not expressly granted are reserved. +# +# This software is distributed under the terms of the GNU General Public +# License v3 (GPL Version 3), copied verbatim in the file "COPYING". +# +# In applying this license CERN does not waive the privileges and immunities +# granted to it by virtue of its status as an Intergovernmental Organization +# or submit itself to any jurisdiction. + +include_guard() + +set(CMAKE_CXX_FLAGS_COVERAGE "-g -O2 -fprofile-arcs -ftest-coverage") +set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_COVERAGE}") +set(CMAKE_Fortran_FLAGS_COVERAGE "-g -O2 -fprofile-arcs -ftest-coverage") +set(CMAKE_LINK_FLAGS_COVERAGE "--coverage -fprofile-arcs -fPIC") + +MARK_AS_ADVANCED( + CMAKE_CXX_FLAGS_COVERAGE + CMAKE_C_FLAGS_COVERAGE + CMAKE_Fortran_FLAGS_COVERAGE + CMAKE_LINK_FLAGS_COVERAGE) + +#Check the compiler and set the compile and link flags +IF (NOT CMAKE_BUILD_TYPE) + Message(STATUS "Set BuildType to DEBUG") + set(CMAKE_BUILD_TYPE Debug) +ENDIF (NOT CMAKE_BUILD_TYPE) + +IF(ENABLE_CASSERT) #For the CI, we want to have assertions enabled + set(CMAKE_CXX_FLAGS_RELEASE "-O2") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") +ELSE() + set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG") + if (CMAKE_BUILD_TYPE STREQUAL "RELEASE" OR CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO") + set(FAIR_MIN_SEVERITY "info") + endif() +ENDIF() +set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") +set(CMAKE_Fortran_FLAGS_RELEASE "-O2") +set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}" CACHE STRING "bla") +set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO "-O2 -g") +# make sure Debug build not optimized (does not seem to work without CACHE + FORCE) +set(CMAKE_CXX_FLAGS_DEBUG "-g -O0" CACHE STRING "Debug mode build flags" FORCE) +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING "Debug mode build flags" FORCE) +set(CMAKE_Fortran_FLAGS_DEBUG "-g -O0" CACHE STRING "Debug mode build flags" FORCE) + +if(APPLE) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,error") # avoid undefined in our libs +elseif(UNIX) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined") # avoid undefined in our libs +endif() + +message(STATUS "Using build type: ${CMAKE_BUILD_TYPE} - CXXFLAGS: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}")