From fb02f37512dd1248d63fe243e36ff3cb9f5c18ec Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Sat, 22 Nov 2025 23:27:22 -0800 Subject: [PATCH] make ASan a compile time option --- CMakeLists.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cc4f088..28b8f5c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,16 @@ set(KE_VERSION "1.0.10") set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wshadow -Werror -std=c99 -g") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DEFAULT_SOURCE -D_XOPEN_SOURCE") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer") + +# Optionally enable AddressSanitizer (ASan) +option(ENABLE_ASAN "Enable AddressSanitizer for builds" OFF) + +if (ENABLE_ASAN) + message(STATUS "ASan enabled") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer") + # Ensure the sanitizer is linked too (especially important on some platforms) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") +endif() # Add executable