Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow checking whether sanitizers are available #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions cmake/FindASan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down
8 changes: 6 additions & 2 deletions cmake/FindMSan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand All @@ -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 ()

Expand Down
31 changes: 31 additions & 0 deletions cmake/FindSanitizers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions cmake/FindTSan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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 ()

Expand Down
9 changes: 5 additions & 4 deletions cmake/FindUBSan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down