From fb4e08ce7117593e4a3af90725deb08bd5313002 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Mon, 16 Mar 2026 23:26:45 +0100 Subject: [PATCH] Tidy up CMake sanitizer flags Set the flags in the build itself instead of trying to override the cache (this was an artifact of when I didn't understand the CMake variable model), which avoids them being duplicated on each re-configuration. Also remove `-g`, since it's defined by the build type by default (we leave it up to the user to choose Debug or RelWithDebInfo). --- CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f42148c..b3ad9599 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,9 +59,10 @@ else() add_compile_options(${SAN_FLAGS}) add_link_options(${SAN_FLAGS}) add_definitions(-D_GLIBCXX_ASSERTIONS -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG) - # A non-zero optimization level is desired in debug mode, but allow overriding it nonetheless - set(CMAKE_CXX_FLAGS_DEBUG "-g -Og -fno-omit-frame-pointer -fno-optimize-sibling-calls ${CMAKE_CXX_FLAGS_DEBUG}" - CACHE STRING "" FORCE) + # A non-zero optimization level is desired even in debug mode (especially for Clang), + # and the two codegen flags improve the sanitizers' backtraces, but we want the user to + # be able to override these easily so we put them first. + string(PREPEND CMAKE_CXX_FLAGS_DEBUG "-Og -fno-omit-frame-pointer -fno-optimize-sibling-calls ") endif() if(MORE_WARNINGS)