add option to build with thread sanitizer

This commit is contained in:
daan 2020-07-21 09:10:45 -07:00
parent 8769082d63
commit 01da026314
1 changed files with 11 additions and 0 deletions

View File

@ -19,6 +19,7 @@ option(MI_BUILD_SHARED "Build shared library" ON)
option(MI_BUILD_STATIC "Build static library" ON)
option(MI_BUILD_OBJECT "Build object library" ON)
option(MI_BUILD_TESTS "Build test executables" ON)
option(MI_DEBUG_TSAN "Build with thread sanitizer (needs clang)" OFF)
option(MI_CHECK_FULL "Use full internal invariant checking in DEBUG mode (deprecated, use MI_DEBUG_FULL instead)" OFF)
include("cmake/mimalloc-config-version.cmake")
@ -133,6 +134,16 @@ if(MI_USE_CXX MATCHES "ON")
endif()
endif()
if(MI_DEBUG_TSAN MATCHES "ON")
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
message(STATUS "Build with thread sanitizer (MI_DEBUG_TSAN=ON)")
list(APPEND mi_cflags -fsanitize=thread -g)
list(APPEND CMAKE_EXE_LINKER_FLAGS -fsanitize=thread)
else()
message(WARNING "Can only use thread sanitizer with clang (MI_DEBUG_TSAN=ON but ignored)")
endif()
endif()
# Compiler flags
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU")
list(APPEND mi_cflags -Wall -Wextra -Wno-unknown-pragmas -fvisibility=hidden)