[llvm] [llvm][cmake] Properly place clang runtime directory on linker command line when WinMsvc.cmake is involved (PR #110084)
Mike Hommey via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 26 00:20:53 PDT 2024
https://github.com/glandium created https://github.com/llvm/llvm-project/pull/110084
WinMsvc.cmake, used for cross-compiling LLVM, targetting Windows, puts -libpath flags on the linker command line for the MSVC directories. Those may contain clang runtime libraries that come from MSVC, and may be incompatible with the clang compiler in use when it doesn't come from MSVC (which is obviously the case on cross-compiles). By prioritizing the clang runtime directory on the linker command line, we avoid those libraries being picked up by the linker.
>From 53afb3a62b482a2f833486d2a77e7c6f642ccc54 Mon Sep 17 00:00:00 2001
From: Mike Hommey <mh at glandium.org>
Date: Thu, 26 Sep 2024 14:24:19 +0900
Subject: [PATCH] [llvm][cmake] Properly place clang runtime directory on
linker command line when WinMsvc.cmake is involved
WinMsvc.cmake, used for cross-compiling LLVM, targetting Windows, puts
-libpath flags on the linker command line for the MSVC directories.
Those may contain clang runtime libraries that come from MSVC, and may
be incompatible with the clang compiler in use when it doesn't come from
MSVC (which is obviously the case on cross-compiles).
By prioritizing the clang runtime directory on the linker command line,
we avoid those libraries being picked up by the linker.
---
llvm/cmake/modules/HandleLLVMOptions.cmake | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index ed13a82905b4e3..e17e2169cd880f 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -324,6 +324,12 @@ function(append value)
endforeach(variable)
endfunction()
+function(prepend value)
+ foreach(variable ${ARGN})
+ set(${variable} "${value} ${${variable}}" PARENT_SCOPE)
+ endforeach(variable)
+endfunction()
+
function(append_if condition value)
if (${condition})
foreach(variable ${ARGN})
@@ -1196,7 +1202,7 @@ if (CLANG_CL AND (LLVM_BUILD_INSTRUMENTED OR LLVM_USE_SANITIZER))
endif()
file(TO_CMAKE_PATH "${clang_compiler_rt_file}" clang_compiler_rt_file)
get_filename_component(clang_runtime_dir "${clang_compiler_rt_file}" DIRECTORY)
- append("/libpath:\"${clang_runtime_dir}\""
+ prepend("/libpath:\"${clang_runtime_dir}\""
CMAKE_EXE_LINKER_FLAGS
CMAKE_MODULE_LINKER_FLAGS
CMAKE_SHARED_LINKER_FLAGS)
More information about the llvm-commits
mailing list