Procházet zdrojové kódy

fix: wire up the ENABLE_ASAN option CLAUDE.md has documented all along

CLAUDE.md's build instructions say
  cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_ASAN=ON ..
but ENABLE_ASAN appeared nowhere in CMakeLists.txt or cmake/ - the flag was
silently ignored and that command produced an ordinary non-sanitized build.
This mattered concretely here: the shutdown fix in this same fix wave was
verified "ASAN clean" during its own development, and anyone re-checking
that claim with the documented command would have gotten a false clean.

Adds the option to cmake/CompilerFlags.cmake, applied globally before any
target is defined, so it covers both smartbotic-webserver and
smartbotic-runner: -fsanitize=address plus -fno-omit-frame-pointer for
readable stack traces on compile, -fsanitize=address on link. Leak detection
rides along with ASAN on Linux rather than needing a separate flag.

Documentation was the thing everyone believed; the option is what was
missing, so the option was added rather than rewriting the doc down to match
reality.
fszontagh před 1 měsícem
rodič
revize
8c43a7dbda
1 změnil soubory, kde provedl 20 přidání a 0 odebrání
  1. 20 0
      cmake/CompilerFlags.cmake

+ 20 - 0
cmake/CompilerFlags.cmake

@@ -52,3 +52,23 @@ endif()
 
 # Position independent code
 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+
+# Address Sanitizer. CLAUDE.md documents
+#   cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_ASAN=ON ..
+# as how to build this project with ASAN - this option is what makes that
+# command actually do it, rather than silently produce an ordinary
+# non-sanitized build (which is exactly what happened before this option
+# existed: the flag was documented but had no matching cmake option, so it
+# was ignored with no error). -fno-omit-frame-pointer keeps ASAN's stack
+# traces readable; leak detection rides along with ASAN on Linux/macOS
+# rather than needing -fsanitize=leak separately.
+option(ENABLE_ASAN "Build with AddressSanitizer (and leak detection) enabled" OFF)
+if(ENABLE_ASAN)
+    if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
+        add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
+        add_link_options(-fsanitize=address)
+    else()
+        message(WARNING "ENABLE_ASAN was requested but the compiler (${CMAKE_CXX_COMPILER_ID}) "
+                         "is not GNU or Clang; AddressSanitizer was not enabled")
+    endif()
+endif()