From 4ddf13a833e8683becb9dc9f4b95426ccfdc475c Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 23 Jun 2024 21:30:59 +0200 Subject: [PATCH] Added the -D_GLIBCXX_ASSERTIONS and -D_FORTIFY_SOURCE=3 options when building using AddressSanitizer or UndefinedBehaviorSanitizer --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d533e95e..5d5aed398 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -269,6 +269,11 @@ if(UBSAN) endif() endif() +if(ASAN OR UBSAN) + # Add some extra checks when building with AddressSanitizer or UndefinedBehaviorSanitizer. + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_ASSERTIONS -D_FORTIFY_SOURCE=3") +endif() + # The following removes half of the ranlib warnings on macOS regarding no symbols for files # that are #ifdef'ed away. There must be a way to remove the other half as well? if(APPLE)