Index: lib/Fuzzer/test/CMakeLists.txt =================================================================== --- lib/Fuzzer/test/CMakeLists.txt +++ lib/Fuzzer/test/CMakeLists.txt @@ -38,6 +38,21 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi") endif() +if(MSVC) + # In order to use the sanitizers in Windows, we need to link against many + # runtime libraries which will depend on the target being created + # (executable or dll) and the c runtime library used (MT/MD). + # By default, cmake uses link.exe for linking, which fails because we don't + # specify the appropiate dependencies. + # As we don't want to consider all of that possible situations which depends + # on the implementation of the compiler-rt, the simplest option is to change + # the rules for linking executables and shared libraries, using the compiler + # instead of link.exe. Clang will consider the sanitizer flags, and + # automatically provide the required libraries to the liker. + set(CMAKE_CXX_LINK_EXECUTABLE " ${CMAKE_CXX_FLAGS} -o /link ") + set(CMAKE_CXX_CREATE_SHARED_LIBRARY " ${CMAKE_CXX_FLAGS} /LD -o /link ") +endif() + # add_libfuzzer_test( # SOURCES source0.cpp [source1.cpp ...] # )