From: Kristina Bessonova Date: Fri, 29 May 2020 11:14:51 +0000 (+0200) Subject: [clang][cmake] Force CMAKE_LINKER for multistage build in case of BOOTSTRAP_LLVM_ENAB... X-Git-Tag: llvmorg-13-init~16627 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ad4ab81dccaa72d9b5137433a0923d325ff76135;p=platform%2Fupstream%2Fllvm.git [clang][cmake] Force CMAKE_LINKER for multistage build in case of BOOTSTRAP_LLVM_ENABLE_LLD and MSVC The issue with LLVM_ENABLE_LLD is that it just passes -fuse-ld=lld to compiler/linker options which makes sense only for those platforms where cmake invokes a compiler driver for linking. On Windows (MSVC) cmake invokes the linker directly and requires CMAKE_LINKER to be specified otherwise it defaults CMAKE_LINKER to be link.exe. This patch allows BOOTSTRAP_LLVM_ENABLE_LLD to set CMAKE_LINKER in two cases: * if building for host Windows, * if crosscompiling for target Windows. It also skips adding '-fuse-ld=lld' to make lld-link not warning about 'unknown argument'. This fixes build with `clang/cmake/caches/DistributionExample.cmake` on Windows. Reviewed By: phosek Differential Revision: https://reviews.llvm.org/D80873 --- diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt index 1a6a20a..0f08538 100644 --- a/clang/CMakeLists.txt +++ b/clang/CMakeLists.txt @@ -753,6 +753,14 @@ if (CLANG_ENABLE_BOOTSTRAP) -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) OR BOOTSTRAP_CMAKE_SYSTEM_NAME STREQUAL "Windows") + set(${CLANG_STAGE}_LINKER -DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/lld-link${CMAKE_EXECUTABLE_SUFFIX}) + 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 index 62dd0ef..89f7016 100644 --- a/llvm/cmake/modules/HandleLLVMOptions.cmake +++ b/llvm/cmake/modules/HandleLLVMOptions.cmake @@ -261,7 +261,12 @@ if( LLVM_ENABLE_LLD ) 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 )