From fbf753257b74072d2c95c10b2f40c0534959cf8d Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Sat, 19 Oct 2024 18:29:05 +0200 Subject: [PATCH] cmake: Add easy sanitizers option Set -DSANITIZE to a comma-separated list of options to pass to -fsanitize=, like -DSANITIZE=address,undefined --- CMakeLists.txt | 1 + cmake/Sanitizers.cmake | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 cmake/Sanitizers.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 40583949..55bf825f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ include(CMakeDependentOption) include(CheckIPOSupported) include(SetupCCache) +include(Sanitizers) set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version") diff --git a/cmake/Sanitizers.cmake b/cmake/Sanitizers.cmake new file mode 100644 index 00000000..9c09da28 --- /dev/null +++ b/cmake/Sanitizers.cmake @@ -0,0 +1,8 @@ +set(SANITIZE "" CACHE STRING "Sanitizers to enable.") + +string(REGEX MATCHALL "[^,]+" ENABLED_SANITIZERS "${SANITIZE}") + +foreach(SANITIZER ${ENABLED_SANITIZERS}) + add_compile_options("-fsanitize=${SANITIZER}") + add_link_options("-fsanitize=${SANITIZER}") +endforeach() \ No newline at end of file