diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f46d07244b87fd6d700d0456d4358cfb67dc3cb..a580b5f486a2163510fc29af62abb8070116b1e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,6 +211,11 @@ if(MSVC OR WIN32) # on windows need append VS_PATH/VC/Tools/Llvm/x64/lib/clang/${CMAKE_CXX_COMPILER_VERSION}/lib/windows # and VS_PATH/VC/Tools/Llvm/lib/clang/${CMAKE_CXX_COMPILER_VERSION}/lib/windows to PATH env if (MGE_BUILD_WITH_ASAN) + message(WARNING "please do (set)export ASAN_OPTIONS=windows_hook_rtl_allocators=true when run test after build finish, caused by we link asan dll!!") + if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") + message(WARNING "Windows AddressSanitizer doesn't support linking with debug runtime libraries yet, which means do not support CMAKE_BUILD_TYPE=Debug") + message(FATAL_ERROR "Please build with RelWithDebInfo or Release by : EXTRA_CMAKE_ARGS=\"-DMGE_BUILD_WITH_ASAN=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo ...\"") + endif() if("$ENV{VS_PATH}" STREQUAL "") message(FATAL_ERROR "can not find VS_PATH, please export Visual Studio root dir to VS_PATH env") endif() @@ -239,6 +244,12 @@ if(MSVC OR WIN32) link_libraries(${WINDOWS_ASAN_DLL_NAME}) link_libraries(${WINDOWS_ASAN_RUNTIME_THUNK_NAME}) set(WIN_FLAGS "/Od -DNDEBUG -fsanitize=address") + # windows Llvm asan do not take effect when /O2 + # RELWITHDEBINFO default value is /O2, so override it + set(CMAKE_C_FLAGS_RELWITHDEBINFO "/Zi /Od /Ob1 /DNDEBUG") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/Zi /Od /Ob1 /DNDEBUG") + set(CMAKE_C_FLAGS_RELEASE "/Zi /Od /Ob1 /DNDEBUG") + set(CMAKE_CXX_FLAGS_RELEASE "/Zi /Od /Ob1 /DNDEBUG") else() set(WIN_FLAGS "/O2") endif()