diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2021-03-22 18:57:16 +0100 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2021-03-26 08:34:55 +0100 |
commit | 5b9a5b84ebefc4baafc784a36099945d9f2de19f (patch) | |
tree | 489fe22f54a15de23f9d5ba488143fc9b9180d75 /cmake | |
parent | bfb7813a9920471091d9b147f3614970a90b60ea (diff) | |
download | ccache-5b9a5b84ebefc4baafc784a36099945d9f2de19f.tar.gz |
Fix fast linker selection
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.
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/UseFastestLinker.cmake | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/cmake/UseFastestLinker.cmake b/cmake/UseFastestLinker.cmake index c96639cb..8f392aac 100644 --- a/cmake/UseFastestLinker.cmake +++ b/cmake/UseFastestLinker.cmake @@ -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() |