[PATCH] D113166: [CMake] Prefer --ld-path when supported

Keith Smiley via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 3 20:36:27 PDT 2021


keith created this revision.
Herald added a subscriber: mgorny.
keith requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This allows relative linker paths, and avoids the warning for path usage
with -fuse-ld. When the compiler doesn't support it this falls back to
the previous behavior.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113166

Files:
  llvm/cmake/modules/HandleLLVMOptions.cmake


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -289,13 +289,19 @@
 
 if( LLVM_USE_LINKER )
   set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
-  set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fuse-ld=${LLVM_USE_LINKER}")
+  set(linker_arg "--ld-path")
+  set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${linker_arg}=${LLVM_USE_LINKER}")
   check_cxx_source_compiles("int main() { return 0; }" CXX_SUPPORTS_CUSTOM_LINKER)
   if ( NOT CXX_SUPPORTS_CUSTOM_LINKER )
-    message(FATAL_ERROR "Host compiler does not support '-fuse-ld=${LLVM_USE_LINKER}'")
+    set(linker_arg "-fuse-ld")
+    set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${linker_arg}=${LLVM_USE_LINKER}")
+    check_cxx_source_compiles("int main() { return 0; }" CXX_SUPPORTS_CUSTOM_LINKER)
+  endif()
+  if ( NOT CXX_SUPPORTS_CUSTOM_LINKER )
+    message(FATAL_ERROR "Host compiler does not support '--ld-path=${LLVM_USE_LINKER}' or '-fuse-ld=${LLVM_USE_LINKER}'")
   endif()
   set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
-  append("-fuse-ld=${LLVM_USE_LINKER}"
+  append("${linker_arg}=${LLVM_USE_LINKER}"
     CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
 endif()
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113166.384647.patch
Type: text/x-patch
Size: 1360 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211104/54febda4/attachment.bin>


More information about the llvm-commits mailing list