From 13c178b7f788b548d48daf894771c1ce48ff0bd1 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Thu, 25 Mar 2021 10:11:54 +0100 Subject: [PATCH] Enabling ASAN on MSVC --- CMakeLists.txt | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dfc180c76..9a5fc8387 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -238,17 +238,23 @@ if (NOT MSVC AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMP add_compile_options(-Wno-unknown-pragmas) endif() - if (SLIC3R_ASAN) - add_compile_options(-fsanitize=address -fno-omit-frame-pointer) +endif() + +if (SLIC3R_ASAN) + # ASAN should be available on MSVC starting with Visual Studio 2019 16.9 + # https://devblogs.microsoft.com/cppblog/address-sanitizer-for-msvc-now-generally-available/ + add_compile_options(-fsanitize=address -fno-omit-frame-pointer) + + if (NOT MSVC) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address") set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=address") - - if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan") - endif () endif () -endif() + + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan") + endif () +endif () if (APPLE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=partial-availability -Werror=unguarded-availability -Werror=unguarded-availability-new")