cmake: Add ThreadSanitizer compile flags
authorAndreas Schneider <asn@samba.org>
Wed, 12 Feb 2020 09:56:13 +0000 (10:56 +0100)
committerStefan Metzmacher <metze@samba.org>
Thu, 28 Jan 2021 14:27:17 +0000 (15:27 +0100)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
cmake/Modules/DefineCompilerFlags.cmake

index 3277b990b6f50b28f4580660feed330f96990348..c92182d570406a6bde9b1113635891cee92adb31 100644 (file)
@@ -34,4 +34,16 @@ if (UNIX AND NOT WIN32)
         CACHE STRING "Flags used by the linker during the creation of shared libraries during UNDEFINEDSANITIZER builds.")
     set(CMAKE_EXEC_LINKER_FLAGS_UNDEFINEDSANITIZER "-fsanitize=undefined"
         CACHE STRING "Flags used by the linker during UNDEFINEDSANITIZER builds.")
+
+    # Activate with: -DCMAKE_BUILD_TYPE=ThreadSanitizer
+    set(CMAKE_C_FLAGS_THREADSANITIZER "-g -O1 -fsanitize=thread"
+        CACHE STRING "Flags used by the C compiler during THREADSANITIZER builds.")
+    set(CMAKE_CXX_FLAGS_THREADSANITIZER "-g -O1 -fsanitize=thread"
+        CACHE STRING "Flags used by the CXX compiler during THREADSANITIZER builds.")
+    set(CMAKE_SHARED_LINKER_FLAGS_THREADSANITIZER "-fsanitize=thread"
+        CACHE STRING "Flags used by the linker during the creation of shared libraries during THREADSANITIZER builds.")
+    set(CMAKE_MODULE_LINKER_FLAGS_THREADSANITIZER "-fsanitize=thread"
+        CACHE STRING "Flags used by the linker during the creation of shared libraries during THREADSANITIZER builds.")
+    set(CMAKE_EXEC_LINKER_FLAGS_THREADSANITIZER "-fsanitize=thread"
+        CACHE STRING "Flags used by the linker during THREADSANITIZER builds.")
 endif()