]> granicus.if.org Git - llvm/commitdiff
[CMake] Fix linker detection in AddLLVM.cmake
authorTim Shen <timshen91@gmail.com>
Mon, 30 Oct 2017 21:12:14 +0000 (21:12 +0000)
committerTim Shen <timshen91@gmail.com>
Mon, 30 Oct 2017 21:12:14 +0000 (21:12 +0000)
Fix linker not being correctly detected when a custom one is specified
through LLVM_USE_LINKER CMake variable.

In particular,

  cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_LINKER=gold ../llvm

resulted into

  Linker detection: GNU ld

instead of

  Linker detection: GNU Gold

due to the construction not accounting for such variable. It led to the general
confusion and prevented setting linker-specific flags inside functions defined
in AddLLVM.cmake.

Thanks Oleksii Vilchanskyi for the patch!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316956 91177308-0d34-0410-b5e6-96231b3b80d8

cmake/modules/AddLLVM.cmake

index f52b1c44ab2713ac21645565c6b36857ecd88f23..62e264e5ef35c4b5ef0acad794fdbba522812a57 100644 (file)
@@ -149,8 +149,13 @@ endfunction(add_llvm_symbol_exports)
 
 if(NOT WIN32 AND NOT APPLE)
   # Detect what linker we have here
+  if( LLVM_USE_LINKER )
+    set(command ${CMAKE_C_COMPILER} -fuse-ld=${LLVM_USE_LINKER} -Wl,--version)
+  else()
+    set(command ${CMAKE_C_COMPILER} -Wl,--version)
+  endif()
   execute_process(
-    COMMAND ${CMAKE_C_COMPILER} -Wl,--version
+    COMMAND ${command}
     OUTPUT_VARIABLE stdout
     ERROR_VARIABLE stderr
     )