summaryrefslogtreecommitdiffstats
path: root/build/build-clang/llvmorg-16-init-15447-g8d3ab9dfc4d4.patch
blob: 76bbebdf723cf8de872054cd1ac763943641053d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
From 8d3ab9dfc4d49062e045d6d5db419975b81da7e4 Mon Sep 17 00:00:00 2001
From: serge-sans-paille <sguelton@mozilla.com>
Date: Thu, 22 Dec 2022 10:48:37 +0100
Subject: [PATCH] Properly support LLVM_ENABLE_LLD on Windows

Currently, setting -DLLVM_ENABLE_LLD=ON on windows also requires setting
-DCMAKE_LINKER=lld-link.exe. This is both misleading and redundant.

Fix this by trying to find llvm-link.exe when -DLLVM_ENABLE_LLD=ON is
set and CMAKE_LINKER is not, and aborting otherwise.

Differential Revision: https://reviews.llvm.org/D140534
---
 llvm/cmake/modules/HandleLLVMOptions.cmake | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 7f141d93d4c2..4f4a64bc02eb 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -293,10 +293,23 @@ 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()
+
   # 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 )
+  if ( MSVC )
+    if(NOT CMAKE_LINKER MATCHES "lld-link")
+        get_filename_component(CXX_COMPILER_DIR ${CMAKE_CXX_COMPILER} DIRECTORY)
+        get_filename_component(C_COMPILER_DIR ${CMAKE_C_COMPILER} DIRECTORY)
+        find_program(LLD_LINK NAMES "lld-link" "lld-link.exe" HINTS ${CXX_COMPILER_DIR} ${C_COMPILER_DIR} DOC "lld linker")
+        if(NOT LLD_LINK)
+            message(FATAL_ERROR
+                "LLVM_ENABLE_LLD set, but cannot find lld-link. "
+                "Consider setting CMAKE_LINKER to lld-link path.")
+        endif()
+        set(CMAKE_LINKER ${LLD_LINK})
+    endif()
+  else()
     set(LLVM_USE_LINKER "lld")
   endif()
 endif()
-- 
2.38.1