Repository navigation
Expand file tree
/
Copy pathO2PhysicsCompileFlags.cmake
More file actions
132 lines (116 loc) · 5.71 KB
/
Copy pathO2PhysicsCompileFlags.cmake
File metadata and controls
132 lines (116 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# 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 "${CMAKE_CXX_FLAGS} -Wall -Wextra")
# Enabled warnings supported by Clang and GCC, not treated as errors
set(O2PHYSICS_WARNINGS_COMMON_NO_ERROR "deprecated-declarations")
# Enabled warnings supported by Clang only, not treated as errors
set(O2PHYSICS_WARNINGS_CLANG_NO_ERROR "vla-extension")
# Enabled warnings supported by GCC only, not treated as errors
set(O2PHYSICS_WARNINGS_GCC_NO_ERROR "")
# Function to build a list of warning flags from their names
function(o2_build_warning_flags)
cmake_parse_arguments(PARSE_ARGV 0 A "" "PREFIX;OUTPUTVARNAME" "WARNINGS")
if(A_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unexpected unparsed arguments: ${A_UNPARSED_ARGUMENTS}")
endif()
list(TRANSFORM A_WARNINGS STRIP)
list(TRANSFORM A_WARNINGS PREPEND ${A_PREFIX})
string(JOIN " " OUTPUT ${A_WARNINGS})
set(${A_OUTPUTVARNAME} ${OUTPUT} PARENT_SCOPE)
endfunction()
message(STATUS "O2PHYSICS_WARNINGS_AS_ERRORS: ${O2PHYSICS_WARNINGS_AS_ERRORS}")
# Treat warnings as errors.
if(O2PHYSICS_WARNINGS_AS_ERRORS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
# Set warning flags for all platforms.
o2_build_warning_flags(PREFIX "-Wno-error="
OUTPUTVARNAME O2PHYSICS_CXX_WARNINGS_COMMON_NO_ERROR
WARNINGS ${O2PHYSICS_WARNINGS_COMMON_NO_ERROR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${O2PHYSICS_CXX_WARNINGS_COMMON_NO_ERROR}")
if(APPLE)
# Set warning flags for macOS only.
o2_build_warning_flags(PREFIX "-Wno-error="
OUTPUTVARNAME O2PHYSICS_CXX_WARNINGS_APPLE_NO_ERROR
WARNINGS ${O2PHYSICS_WARNINGS_CLANG_NO_ERROR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${O2PHYSICS_CXX_WARNINGS_APPLE_NO_ERROR}")
elseif(UNIX)
# Set warning flags for Linux only.
o2_build_warning_flags(PREFIX "-Wno-error="
OUTPUTVARNAME O2PHYSICS_CXX_WARNINGS_UNIX_NO_ERROR
WARNINGS ${O2PHYSICS_WARNINGS_GCC_NO_ERROR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${O2PHYSICS_CXX_WARNINGS_UNIX_NO_ERROR}")
endif()
endif()
IF (ENABLE_TIMETRACE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftime-trace")
ENDIF()
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 RELWITHDEBINFO)
ENDIF (NOT CMAKE_BUILD_TYPE)
# Adjust the per-config flags rather than replacing them. These used to be plain
# set() calls, which create normal variables that shadow the cache for the rest of
# the configure -- so whatever the build recipe passed as
# -DCMAKE_CXX_FLAGS_RELWITHDEBINFO=... was silently discarded. alidist asks for
# "-O2 -g1 -DNDEBUG" (overridable via O2PHYSICS_DEBUG_FLAGS) and got -g anyway;
# full debug info costs ~18% of total compile time across the tree, because the
# register allocator's rewrite pass scales with the number of debug records.
# Here we only enforce what this project actually cares about: -pipe, and whether
# NDEBUG is defined. The optimisation and debug-info levels stay as given.
function(o2physics_adjust_config_flags varname want_ndebug)
set(flags "${${varname}}")
if(want_ndebug)
if(NOT flags MATCHES "(^| )-DNDEBUG($| )")
string(APPEND flags " -DNDEBUG")
endif()
else()
# ENABLE_CASSERT: the CI wants <cassert> assertions live.
string(REGEX REPLACE "(^| )-DNDEBUG($| )" " " flags "${flags}")
endif()
if(NOT flags MATCHES "(^| )-pipe($| )")
string(APPEND flags " -pipe")
endif()
string(STRIP "${flags}" flags)
set(${varname} "${flags}" PARENT_SCOPE)
endfunction()
IF(ENABLE_CASSERT) #For the CI, we want to have <cassert> assertions enabled
o2physics_adjust_config_flags(CMAKE_CXX_FLAGS_RELEASE FALSE)
o2physics_adjust_config_flags(CMAKE_CXX_FLAGS_RELWITHDEBINFO FALSE)
ELSE()
o2physics_adjust_config_flags(CMAKE_CXX_FLAGS_RELEASE TRUE)
o2physics_adjust_config_flags(CMAKE_CXX_FLAGS_RELWITHDEBINFO TRUE)
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_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)
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}}")