diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt --- a/clang/CMakeLists.txt +++ b/clang/CMakeLists.txt @@ -745,6 +745,14 @@ -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/${C_COMPILER} -DCMAKE_ASM_COMPILER_ID=Clang) + # cmake requires CMAKE_LINKER to be specified if the compiler is MSVC-like, + # otherwise it defaults the linker to be link.exe. + if(BOOTSTRAP_LLVM_ENABLE_LLD) + if(WIN32 AND NOT BOOTSTRAP_CMAKE_SYSTEM_NAME) + set(${CLANG_STAGE}_LINKER -DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/lld-link.exe) + endif() + endif() + if(BOOTSTRAP_CMAKE_SYSTEM_NAME) set(${CLANG_STAGE}_CONFIG -DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config) set(${CLANG_STAGE}_TABLEGEN diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake --- a/llvm/cmake/modules/HandleLLVMOptions.cmake +++ b/llvm/cmake/modules/HandleLLVMOptions.cmake @@ -261,7 +261,12 @@ if ( LLVM_USE_LINKER ) message(FATAL_ERROR "LLVM_ENABLE_LLD and LLVM_USE_LINKER can't be set at the same time") endif() - set(LLVM_USE_LINKER "lld") + # In case of MSVC cmake always invokes the linker directly, so the linker + # should be specified by CMAKE_LINKER cmake variable instead of by -fuse-ld + # compiler option. + if ( NOT MSVC ) + set(LLVM_USE_LINKER "lld") + endif() endif() if( LLVM_USE_LINKER )