Allow checking whether sanitizers are available

This commit is contained in:
Andrei Astafev 2019-07-02 09:33:34 +03:00
parent 99e159ec9b
commit 82086416a0
6 changed files with 54 additions and 13 deletions

View File

@ -39,13 +39,15 @@ if (SANITIZE_ADDRESS AND (SANITIZE_THREAD OR SANITIZE_MEMORY))
"ThreadSanitizer or MemorySanitizer.")
endif ()
include(sanitize-helpers)
if (SANITIZE_ADDRESS)
sanitizer_check_compiler_flags("${FLAG_CANDIDATES}" "AddressSanitizer"
"ASan")
sanitizer_check_compiler_flags("${FLAG_CANDIDATES}" "AddressSanitizer" "ASan")
if(ASan_FLAG_DETECTED)
set(ASan_FOUND TRUE)
endif()
if (SANITIZE_ADDRESS)
find_program(ASan_WRAPPER "asan-wrapper" PATHS ${CMAKE_MODULE_PATH})
mark_as_advanced(ASan_WRAPPER)
endif ()

View File

@ -31,6 +31,12 @@ set(FLAG_CANDIDATES
include(sanitize-helpers)
sanitizer_check_compiler_flags("${FLAG_CANDIDATES}" "MemorySanitizer" "MSan")
if(MSan_FLAG_DETECTED)
set(MSan_FOUND TRUE)
endif()
if (SANITIZE_MEMORY)
if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
message(WARNING "MemorySanitizer disabled for target ${TARGET} because "
@ -43,8 +49,6 @@ if (SANITIZE_MEMORY)
set(SANITIZE_MEMORY Off CACHE BOOL
"Enable MemorySanitizer for sanitized targets." FORCE)
else ()
sanitizer_check_compiler_flags("${FLAG_CANDIDATES}" "MemorySanitizer"
"MSan")
endif ()
endif ()

31
cmake/FindSanitizers.cmake Executable file → Normal file
View File

@ -40,6 +40,37 @@ find_package(MSan ${FIND_QUIETLY_FLAG})
find_package(UBSan ${FIND_QUIETLY_FLAG})
set(Sanitizers_COMPONENTS "")
if(ASan_FOUND)
set(Sanitizers_ASan_FOUND TRUE)
list(APPEND Sanitizers_COMPONENTS ASan)
endif()
if(TSan_FOUND)
set(Sanitizers_TSan_FOUND TRUE)
list(APPEND Sanitizers_COMPONENTS TSan)
endif()
if(MSan_FOUND)
set(Sanitizers_MSan_FOUND TRUE)
list(APPEND Sanitizers_COMPONENTS MSan)
endif()
if(UBSan_FOUND)
set(Sanitizers_UBSan_FOUND TRUE)
list(APPEND Sanitizers_COMPONENTS UBSan)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
Sanitizers
FOUND_VAR Sanitizers_FOUND
REQUIRED_VARS Sanitizers_COMPONENTS
HANDLE_COMPONENTS
)
function(sanitizer_add_blacklist_file FILE)

View File

@ -38,6 +38,12 @@ endif ()
include(sanitize-helpers)
sanitizer_check_compiler_flags("${FLAG_CANDIDATES}" "ThreadSanitizer" "TSan")
if(TSan_FLAG_DETECTED)
set(TSan_FOUND TRUE)
endif()
if (SANITIZE_THREAD)
if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND
NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
@ -50,9 +56,6 @@ if (SANITIZE_THREAD)
"ThreadSanitizer is supported for 64bit systems only.")
set(SANITIZE_THREAD Off CACHE BOOL
"Enable ThreadSanitizer for sanitized targets." FORCE)
else ()
sanitizer_check_compiler_flags("${FLAG_CANDIDATES}" "ThreadSanitizer"
"TSan")
endif ()
endif ()

View File

@ -32,10 +32,11 @@ set(FLAG_CANDIDATES
include(sanitize-helpers)
if (SANITIZE_UNDEFINED)
sanitizer_check_compiler_flags("${FLAG_CANDIDATES}"
"UndefinedBehaviorSanitizer" "UBSan")
endif ()
sanitizer_check_compiler_flags("${FLAG_CANDIDATES}" "UndefinedBehaviorSanitizer" "UBSan")
if(UBSan_FLAG_DETECTED)
set(UBSan_FOUND TRUE)
endif()
function (add_sanitize_undefined TARGET)
if (NOT SANITIZE_UNDEFINED)

0
cmake/sanitize-helpers.cmake Executable file → Normal file
View File