diff options
Diffstat (limited to 'cmake/Sanitizer.cmake')
| -rw-r--r-- | cmake/Sanitizer.cmake | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/cmake/Sanitizer.cmake b/cmake/Sanitizer.cmake new file mode 100644 index 0000000..6e633a9 --- /dev/null +++ b/cmake/Sanitizer.cmake @@ -0,0 +1,28 @@ +# cmake/Sanitizers.cmake +# +# Adds sanitizers compile/link flags when requested. +# Usage: include(Sanitizers) ; enable_sanitizers(<target>) + +function(enable_sanitizers target) + if (NOT BOLTDBG_ENABLE_ASAN) + message(VERBOSE "Sanitizers disabled (BOLTDBG_ENABLE_ASAN=OFF)") + return() + endif() + + if (MSVC) + message(WARNING "AddressSanitizer is not fully supported on MSVC. Skipping.") + return() + endif() + + # AddressSanitizer + UndefinedBehaviorSanitizer recommended combo + target_compile_options(${target} PRIVATE -fsanitize=address,undefined -fno-omit-frame-pointer) + target_link_options(${target} PRIVATE -fsanitize=address,undefined) + + # Optional: ThreadSanitizer for race conditions (enable manually if needed) + # target_compile_options(${target} PRIVATE -fsanitize=thread -fno-omit-frame-pointer) + # target_link_options(${target} PRIVATE -fsanitize=thread) + + # Recommended debug symbols + target_compile_options(${target} PRIVATE -g) + message(STATUS "Enabled AddressSanitizer and UndefinedBehaviorSanitizer for target ${target}") +endfunction() |
