Skip to content

Commit 631bcbe

Browse files
authored
[llvm][cmake] Properly place clang runtime directory on linker command line when WinMsvc.cmake is involved (llvm#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.
1 parent 8a7843c commit 631bcbe

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,12 @@ function(append value)
324324
endforeach(variable)
325325
endfunction()
326326

327+
function(prepend value)
328+
foreach(variable ${ARGN})
329+
set(${variable} "${value} ${${variable}}" PARENT_SCOPE)
330+
endforeach(variable)
331+
endfunction()
332+
327333
function(append_if condition value)
328334
if (${condition})
329335
foreach(variable ${ARGN})
@@ -1196,7 +1202,7 @@ if (CLANG_CL AND (LLVM_BUILD_INSTRUMENTED OR LLVM_USE_SANITIZER))
11961202
endif()
11971203
file(TO_CMAKE_PATH "${clang_compiler_rt_file}" clang_compiler_rt_file)
11981204
get_filename_component(clang_runtime_dir "${clang_compiler_rt_file}" DIRECTORY)
1199-
append("/libpath:\"${clang_runtime_dir}\""
1205+
prepend("/libpath:\"${clang_runtime_dir}\""
12001206
CMAKE_EXE_LINKER_FLAGS
12011207
CMAKE_MODULE_LINKER_FLAGS
12021208
CMAKE_SHARED_LINKER_FLAGS)

0 commit comments

Comments
 (0)