From a09defec4c093103cd33a7b70bc43449a3f9171d Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Tue, 7 Feb 2017 15:07:54 +0100 Subject: [PATCH] CMake: Add ENABLE_SANITIZERS flag Enabling this flag enables AddressSanitizer and UndefinedBehaviorSanitizer --- CMakeLists.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e40c750..f464962 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,21 @@ if (ENABLE_CUSTOM_COMPILER_FLAGS) ) endif() +option(ENABLE_SANITIZERS "Enables AddressSanitizer and UndefinedBehaviorSanitizer." OFF) +if (ENABLE_SANITIZERS) + list(APPEND custom_compiler_flags + -fno-omit-frame-pointer + -fsanitize=address + -fsanitize=undefined + -fsanitize=float-divide-by-zero + -fsanitize=float-cast-overflow + -fsanitize-address-use-after-scope + -fsanitize=integer + -01 + -fno-sanitize-recover + ) +endif() + # apply custom compiler flags foreach(compiler_flag ${custom_compiler_flags}) #remove problematic characters -- GitLab