diff --git a/cmake/FindASan.cmake b/cmake/FindASan.cmake index 98ea7cb..a6a7277 100644 --- a/cmake/FindASan.cmake +++ b/cmake/FindASan.cmake @@ -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 () diff --git a/cmake/FindMSan.cmake b/cmake/FindMSan.cmake index 22d0050..57f85ba 100644 --- a/cmake/FindMSan.cmake +++ b/cmake/FindMSan.cmake @@ -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 () diff --git a/cmake/FindSanitizers.cmake b/cmake/FindSanitizers.cmake old mode 100755 new mode 100644 index 101bab8..a84a8af --- a/cmake/FindSanitizers.cmake +++ b/cmake/FindSanitizers.cmake @@ -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) diff --git a/cmake/FindTSan.cmake b/cmake/FindTSan.cmake index 3cba3c0..d87857a 100644 --- a/cmake/FindTSan.cmake +++ b/cmake/FindTSan.cmake @@ -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 () diff --git a/cmake/FindUBSan.cmake b/cmake/FindUBSan.cmake index ae103f7..d9ec84d 100644 --- a/cmake/FindUBSan.cmake +++ b/cmake/FindUBSan.cmake @@ -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) diff --git a/cmake/sanitize-helpers.cmake b/cmake/sanitize-helpers.cmake old mode 100755 new mode 100644