diff options
author | Felix Weilbach <felix.weilbach@nextcloud.com> | 2021-04-23 10:33:51 +0200 |
---|---|---|
committer | Sergio Martins <smartins@kde.org> | 2021-05-21 13:50:23 +0000 |
commit | 08faec5d95ef50a1dd6f3e97dc2b73690668ed9d (patch) | |
tree | b940b3f731185bf9865e09d573e7e30349d989b8 /modules | |
parent | f7b1cf93e67e3eba07597bf7891b854bd8c954ba (diff) | |
download | extra-cmake-modules-08faec5d95ef50a1dd6f3e97dc2b73690668ed9d.tar.gz extra-cmake-modules-08faec5d95ef50a1dd6f3e97dc2b73690668ed9d.tar.bz2 |
Add address sanitizer for MSVC
Diffstat (limited to 'modules')
-rw-r--r-- | modules/ECMEnableSanitizers.cmake | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/modules/ECMEnableSanitizers.cmake b/modules/ECMEnableSanitizers.cmake index db368863..84f1819c 100644 --- a/modules/ECMEnableSanitizers.cmake +++ b/modules/ECMEnableSanitizers.cmake @@ -76,7 +76,7 @@ Since 1.3.0. # MACRO check_compiler_version #----------------------------- -macro (check_compiler_version gcc_required_version clang_required_version) +macro (check_compiler_version gcc_required_version clang_required_version msvc_required_version) if ( ( CMAKE_CXX_COMPILER_ID MATCHES "GNU" @@ -89,12 +89,19 @@ macro (check_compiler_version gcc_required_version clang_required_version) AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${clang_required_version} ) + OR + ( + CMAKE_CXX_COMPILER_ID MATCHES "MSVC" + AND + CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${msvc_required_version} + ) ) # error ! message(FATAL_ERROR "You ask to enable the sanitizer ${CUR_SANITIZER}, but your compiler ${CMAKE_CXX_COMPILER_ID} version ${CMAKE_CXX_COMPILER_VERSION} does not support it ! - You should use at least GCC ${gcc_required_version} or Clang ${clang_required_version} + You should use at least GCC ${gcc_required_version}, Clang ${clang_required_version} + or MSVC ${msvc_required_version} (99.99 means not implemented yet)") endif () endmacro () @@ -103,25 +110,29 @@ endmacro () #------------------------------ macro (enable_sanitizer_flags sanitize_option) if (${sanitize_option} MATCHES "address") - check_compiler_version("4.8" "3.1") - set(XSAN_COMPILE_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls") - set(XSAN_LINKER_FLAGS "asan") + check_compiler_version("4.8" "3.1" "19.28") + if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + set(XSAN_COMPILE_FLAGS "-fsanitize=address") + else() + set(XSAN_COMPILE_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls") + set(XSAN_LINKER_FLAGS "asan") + endif() elseif (${sanitize_option} MATCHES "thread") - check_compiler_version("4.8" "3.1") + check_compiler_version("4.8" "3.1" "99.99") set(XSAN_COMPILE_FLAGS "-fsanitize=thread") set(XSAN_LINKER_FLAGS "tsan") elseif (${sanitize_option} MATCHES "memory") - check_compiler_version("99.99" "3.1") + check_compiler_version("99.99" "3.1" "99.99") set(XSAN_COMPILE_FLAGS "-fsanitize=memory") elseif (${sanitize_option} MATCHES "leak") - check_compiler_version("4.9" "3.4") + check_compiler_version("4.9" "3.4" "99.99") set(XSAN_COMPILE_FLAGS "-fsanitize=leak") set(XSAN_LINKER_FLAGS "lsan") elseif (${sanitize_option} MATCHES "undefined") - check_compiler_version("4.9" "3.1") + check_compiler_version("4.9" "3.1" "99.99") set(XSAN_COMPILE_FLAGS "-fsanitize=undefined -fno-omit-frame-pointer -fno-optimize-sibling-calls") elseif (${sanitize_option} MATCHES "fuzzer") - check_compiler_version("99.99" "6.0") + check_compiler_version("99.99" "6.0" "99.99") set(XSAN_COMPILE_FLAGS "-fsanitize=fuzzer") else () message(FATAL_ERROR "Compiler sanitizer option \"${sanitize_option}\" not supported.") @@ -129,7 +140,7 @@ macro (enable_sanitizer_flags sanitize_option) endmacro () if (ECM_ENABLE_SANITIZERS) - if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "MSVC") # for each element of the ECM_ENABLE_SANITIZERS list foreach ( CUR_SANITIZER ${ECM_ENABLE_SANITIZERS} ) # lowercase filter |