|
@@ -52,3 +52,23 @@ endif()
|
|
|
|
|
|
|
|
# Position independent code
|
|
# Position independent code
|
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
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()
|