From 187355702bdfd8e4fa305bf5338311730efaf60b Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sun, 2 May 2021 13:05:01 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20CMake:=20Add=20ThreadSanitizer?= =?UTF-8?q?=20via=20`-DTSAN=3DON=20-DASAN=3DOFF`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It immediately detects some data races --- CMakeLists.txt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cd3bc617d..ab79a3130 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ include(CMake/genex.cmake) DEBUG_OPTION(ASAN "Enable address sanitizer") DEBUG_OPTION(UBSAN "Enable undefined behaviour sanitizer") +option(TSAN "Enable thread sanitizer (not compatible with ASAN=ON)" OFF) DEBUG_OPTION(DEBUG "Enable debug mode in engine") option(GPERF "Build with GPerfTools profiler" OFF) option(DISABLE_LTO "Disable link-time optimization (by default enabled in release mode)" OFF) @@ -631,13 +632,19 @@ foreach( endif() endforeach(def_name) -genex_for_option(ASAN) genex_for_option(UBSAN) -target_compile_options(${BIN_TARGET} PUBLIC "$<${ASAN_GENEX}:-fsanitize=address;-fsanitize-recover=address>") -target_link_libraries(${BIN_TARGET} PUBLIC "$<${ASAN_GENEX}:-fsanitize=address;-fsanitize-recover=address>") target_compile_options(${BIN_TARGET} PUBLIC $<${UBSAN_GENEX}:-fsanitize=undefined>) target_link_libraries(${BIN_TARGET} PUBLIC $<${UBSAN_GENEX}:-fsanitize=undefined>) +if(TSAN) + target_compile_options(${BIN_TARGET} PUBLIC -fsanitize=thread) + target_link_libraries(${BIN_TARGET} PUBLIC -fsanitize=thread) +else() + genex_for_option(ASAN) + target_compile_options(${BIN_TARGET} PUBLIC "$<${ASAN_GENEX}:-fsanitize=address;-fsanitize-recover=address>") + target_link_libraries(${BIN_TARGET} PUBLIC "$<${ASAN_GENEX}:-fsanitize=address;-fsanitize-recover=address>") +endif() + if(USE_SDL1) target_link_libraries(${BIN_TARGET} PRIVATE ${SDL_TTF_LIBRARY}