Skip to content

Commit 3264d4a

Browse files
authored
[Infrastructure] Properly adapt flags in case of ENABLE_ASSERT (#18329)
1 parent dff5492 commit 3264d4a

1 file changed

Lines changed: 30 additions & 4 deletions

File tree

‎dependencies/O2PhysicsCompileFlags.cmake‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,38 @@ IF (NOT CMAKE_BUILD_TYPE)
8080
set(CMAKE_BUILD_TYPE RELWITHDEBINFO)
8181
ENDIF (NOT CMAKE_BUILD_TYPE)
8282

83+
# Adjust the per-config flags rather than replacing them. These used to be plain
84+
# set() calls, which create normal variables that shadow the cache for the rest of
85+
# the configure -- so whatever the build recipe passed as
86+
# -DCMAKE_CXX_FLAGS_RELWITHDEBINFO=... was silently discarded. alidist asks for
87+
# "-O2 -g1 -DNDEBUG" (overridable via O2PHYSICS_DEBUG_FLAGS) and got -g anyway;
88+
# full debug info costs ~18% of total compile time across the tree, because the
89+
# register allocator's rewrite pass scales with the number of debug records.
90+
# Here we only enforce what this project actually cares about: -pipe, and whether
91+
# NDEBUG is defined. The optimisation and debug-info levels stay as given.
92+
function(o2physics_adjust_config_flags varname want_ndebug)
93+
set(flags "${${varname}}")
94+
if(want_ndebug)
95+
if(NOT flags MATCHES "(^| )-DNDEBUG($| )")
96+
string(APPEND flags " -DNDEBUG")
97+
endif()
98+
else()
99+
# ENABLE_CASSERT: the CI wants <cassert> assertions live.
100+
string(REGEX REPLACE "(^| )-DNDEBUG($| )" " " flags "${flags}")
101+
endif()
102+
if(NOT flags MATCHES "(^| )-pipe($| )")
103+
string(APPEND flags " -pipe")
104+
endif()
105+
string(STRIP "${flags}" flags)
106+
set(${varname} "${flags}" PARENT_SCOPE)
107+
endfunction()
108+
83109
IF(ENABLE_CASSERT) #For the CI, we want to have <cassert> assertions enabled
84-
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -pipe")
85-
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -pipe")
110+
o2physics_adjust_config_flags(CMAKE_CXX_FLAGS_RELEASE FALSE)
111+
o2physics_adjust_config_flags(CMAKE_CXX_FLAGS_RELWITHDEBINFO FALSE)
86112
ELSE()
87-
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG -pipe")
88-
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG -pipe")
113+
o2physics_adjust_config_flags(CMAKE_CXX_FLAGS_RELEASE TRUE)
114+
o2physics_adjust_config_flags(CMAKE_CXX_FLAGS_RELWITHDEBINFO TRUE)
89115
if (CMAKE_BUILD_TYPE STREQUAL "RELEASE" OR CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
90116
set(FAIR_MIN_SEVERITY "info")
91117
endif()

0 commit comments

Comments
 (0)