diff --git a/CMakeLists.txt b/CMakeLists.txt index efc75e905..76f749a7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,6 +92,7 @@ mark_as_advanced( option(BUILD_TEST_SUITE "Build the test suite" 0) option(BUILD_MAN "Build man pages" 1) +option(ASAN "DEBUGGING: Build with AddressSanitizer (ASan) support" 0) set(ZM_RUNDIR "/var/run/zm" CACHE PATH "Location of transient process files, default: /var/run/zm") diff --git a/cmake/compiler/clang/settings.cmake b/cmake/compiler/clang/settings.cmake index 1d6a0e8f4..c8d90ae0f 100644 --- a/cmake/compiler/clang/settings.cmake +++ b/cmake/compiler/clang/settings.cmake @@ -1,3 +1,21 @@ target_compile_options(zm-warning-interface INTERFACE -Wall) + +if(ASAN) + target_compile_options(zm-compile-option-interface + INTERFACE + -fno-omit-frame-pointer + -fsanitize=address + -fsanitize-recover=address + -fsanitize-address-use-after-scope) + + target_link_options(zm-compile-option-interface + INTERFACE + -fno-omit-frame-pointer + -fsanitize=address + -fsanitize-recover=address + -fsanitize-address-use-after-scope) + + message(STATUS "Clang: Enabled AddressSanitizer (ASan)") +endif() diff --git a/cmake/compiler/gcc/settings.cmake b/cmake/compiler/gcc/settings.cmake index 1d6a0e8f4..ecdf31caa 100644 --- a/cmake/compiler/gcc/settings.cmake +++ b/cmake/compiler/gcc/settings.cmake @@ -1,3 +1,21 @@ target_compile_options(zm-warning-interface INTERFACE -Wall) + +if(ASAN) + target_compile_options(zm-compile-option-interface + INTERFACE + -fno-omit-frame-pointer + -fsanitize=address + -fsanitize-recover=address + -fsanitize-address-use-after-scope) + + target_link_options(zm-compile-option-interface + INTERFACE + -fno-omit-frame-pointer + -fsanitize=address + -fsanitize-recover=address + -fsanitize-address-use-after-scope) + + message(STATUS "GCC: Enabled AddressSanitizer (ASan)") +endif()