diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ac8a0c6..6eeb68a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -188,6 +188,7 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") endif() # https://clang.llvm.org/docs/AddressSanitizer.html +# https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#index-fsanitize_003daddress option(ACL_WITH_ASAN "Build with address sanitizer" OFF) message(STATUS "Build with address sanitizer: ${ACL_WITH_ASAN}") if(ACL_WITH_ASAN) @@ -200,6 +201,20 @@ if(ACL_WITH_ASAN) endforeach() endif() +# https://clang.llvm.org/docs/ThreadSanitizer.html +# https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#index-fsanitize_003dthread +option(ACL_TSAN "Build with thread sanitizer" OFF) +message(STATUS "Build with thread sanitizer: ${ACL_TSAN}") +if(ACL_TSAN) + foreach(lang C CXX) + if(CMAKE_${lang}_COMPILER_ID MATCHES "^(Clang|GNU)$") + set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} -fsanitize=thread -fno-omit-frame-pointer") + else() + message(FATAL_ERROR "cannot build with thread sanitizer due to unsupported ${lang} compiler") + endif() + endforeach() +endif() + include(CPack) include(CTest)