From 6c110e4d0cfa7248681f641fa7240b9aa48d0b00 Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Fri, 16 Oct 2026 14:36:44 +0200 Subject: [PATCH] Properly adapt flags in case of ENABLE_ASSERT --- dependencies/O2PhysicsCompileFlags.cmake | 34 +++++++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/dependencies/O2PhysicsCompileFlags.cmake b/dependencies/O2PhysicsCompileFlags.cmake index 3aff4b73547..111ddb1bacd 100644 --- a/dependencies/O2PhysicsCompileFlags.cmake +++ b/dependencies/O2PhysicsCompileFlags.cmake @@ -80,12 +80,38 @@ IF (NOT CMAKE_BUILD_TYPE) 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 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 assertions enabled - set(CMAKE_CXX_FLAGS_RELEASE "-O2 -pipe") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -pipe") + o2physics_adjust_config_flags(CMAKE_CXX_FLAGS_RELEASE FALSE) + o2physics_adjust_config_flags(CMAKE_CXX_FLAGS_RELWITHDEBINFO FALSE) ELSE() - set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG -pipe") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG -pipe") + 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()