]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Fix fast linker selection
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 22 Mar 2021 17:57:16 +0000 (18:57 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 26 Mar 2021 07:34:55 +0000 (08:34 +0100)
This partially reverts commit 6b552a3247e285dd5a4b1c21b3afc3f38ce68161.

As noted in #788, the fix in 6b552a32 doesn’t work. However, I can’t
reproduce any problems with the original solution so let’s revert back
to it.

Fixes #794.

cmake/UseFastestLinker.cmake

index c96639cb13c5bba025f9f83854456a22a36e63e1..8f392aac3ed4e7c40b9e0772f2aa378b929afef2 100644 (file)
@@ -11,20 +11,19 @@ function(use_fastest_linker)
     message(WARNING "use_fastest_linker() disabled, as it is not called at the project top level")
     return()
   endif()
-  find_program(FASTER_LINKER ld.lld)
-  if(NOT FASTER_LINKER)
-    find_program(FASTER_LINKER ld.gold)
-  endif()
-  if(FASTER_LINKER)
-    # Note: Compiler flag -fuse-ld requires gcc 9 or clang 3.8.
-    #       Instead override CMAKE_CXX_LINK_EXECUTABLE directly.
-    #       By default CMake uses the compiler executable for linking.
-    set(CMAKE_CXX_LINK_EXECUTABLE "${FASTER_LINKER} <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
-    message_verbose("Using ${FASTER_LINKER} linker for faster linking")
+
+  find_program(HAS_LD_LLD ld.lld)
+  if(HAS_LD_LLD)
+    link_libraries(-fuse-ld=lld)
+    message_verbose("Using lld linker for faster linking")
   else()
-    message_verbose("Using default linker")
+    find_program(HAS_LD_GOLD ld.gold)
+    if(HAS_LD_GOLD)
+      link_libraries(-fuse-ld=gold)
+      message_verbose("Using gold linker for faster linking")
+    else()
+      message_verbose("Using default linker")
+    endif()
   endif()
 endfunction()