[CMake] Fix runtimes cross-compilation when using LLVM_USE_LINKER
authorVincent Lee <leevince@fb.com>
Wed, 3 Aug 2022 07:00:02 +0000 (00:00 -0700)
committerVincent Lee <leevince@fb.com>
Wed, 3 Aug 2022 18:24:09 +0000 (11:24 -0700)
This is motivated by https://reviews.llvm.org/D115852#3226050 where passing
`LLVM_USE_LINKER` in PASSTHROUGH_PREFIXES breaks cross-compilation
(e.g. targeting Windows on a Linux host). As suggested on that diff, implement
an override for it by allowing users to pass `RUNTIMES_${target}_LLVM_USE_LINKER`
to specify the linker for runtimes. Defaults to host linker if not specified.

Reviewed By: phosek, smeenai

Differential Revision: https://reviews.llvm.org/D131051

llvm/runtimes/CMakeLists.txt

index 34fccca..d904121 100644 (file)
@@ -346,6 +346,10 @@ function(runtime_register_target name target)
     list(APPEND ${name}_extra_args -DLLVM_ENABLE_RUNTIMES=${LLVM_ENABLE_RUNTIMES_PASSTHROUGH})
   endif()
 
+  if(NOT RUNTIMES_${name}_LLVM_USE_LINKER AND NOT RUNTIMES_${target}_LLVM_USE_LINKER)
+    list(APPEND ${name}_extra_args -DLLVM_USE_LINKER=${LLVM_USE_LINKER})
+  endif()
+
   llvm_ExternalProject_Add(runtimes-${name}
                            ${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes
                            DEPENDS ${${name}_deps}
@@ -362,7 +366,6 @@ function(runtime_register_target name target)
                                       -DLLVM_RUNTIMES_TARGET=${name}
                                       ${COMMON_CMAKE_ARGS}
                                       ${${name}_extra_args}
-                           PASSTHROUGH_PREFIXES LLVM_USE_LINKER
                            EXTRA_TARGETS ${${name}_extra_targets}
                                          ${${name}_test_targets}
                            USE_TOOLCHAIN