File: detect-thread-sanitizer.patch

package info (click to toggle)
xenium 0.0.2%2Bds-9
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,152 kB
  • sloc: cpp: 12,299; makefile: 20
file content (42 lines) | stat: -rw-r--r-- 1,271 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Description: Check whether TSan works before trying to use it
 because not all Debian archs support it.
Author: Juhani Numminen <juhaninumminen0@gmail.com>
Forwarded: https://github.com/mpoeter/xenium/pull/21
Last-Update: 2020-12-30
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,9 @@
 project(xenium)
 cmake_minimum_required(VERSION 3.0)
 
+include(CheckCXXCompilerFlag)
+include(CMakePushCheckState)
+
 include(gtest.cmake)
 
 set(CMAKE_CXX_STANDARD 17)
@@ -11,6 +14,7 @@
 find_package(Threads REQUIRED)
 find_package(Doxygen)
 
+option(WITH_TSAN "Build tests and benchmarks with ThreadSanitizer" ON)
 option(BUILD_DOCUMENTATION "Create the HTML based documentation (requires Doxygen)" ${DOXYGEN_FOUND})
 
 file(GLOB_RECURSE XENIUM_FILES xenium/*.hpp)
@@ -43,6 +47,16 @@
 	target_compile_definitions(benchmark PRIVATE WITH_LIBCDS CDS_THREADING_CXX11)
 endif()
 
+if(WITH_TSAN AND NOT MSVC)
+	cmake_push_check_state()
+	set(CMAKE_REQUIRED_FLAGS -fsanitize=thread)
+	check_cxx_compiler_flag("" TSAN_FLAG_WORKS)
+	cmake_pop_check_state()
+	if(TSAN_FLAG_WORKS)
+		string(APPEND CMAKE_CXX_FLAGS " -fsanitize=thread")
+	endif()
+endif()
+
 if(MSVC)
 	target_compile_options(gtest PRIVATE /bigobj /W4)# /WX)
 	target_compile_options(benchmark PRIVATE /bigobj)# /W4 /WX)