From 8c8e1ebdd2c3a12f3860a1a8202b74bb7f028420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 16 Jun 2023 10:33:30 +0200 Subject: [PATCH] CMake: Use lld when using Clang compiler When using the `WITH_LINKER_LLD` option, the logic to find the `ld.lld` binary and actually tell the build system to use it was specific to GCC. I've copied the Clang-specific logic for Mold and adjusted it to find LLD. Not entirely sure why this is necessary, as LLD is actually Clang's linker. However, without this change, CMake would use regular old slow `ld` to link. Pull Request: https://projects.blender.org/blender/blender/pulls/108884 --- .../cmake/platform/platform_unix.cmake | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/build_files/cmake/platform/platform_unix.cmake b/build_files/cmake/platform/platform_unix.cmake index 798dbb310e8..19d777f252c 100644 --- a/build_files/cmake/platform/platform_unix.cmake +++ b/build_files/cmake/platform/platform_unix.cmake @@ -928,6 +928,27 @@ elseif(CMAKE_C_COMPILER_ID MATCHES "Clang") unset(MOLD_BIN) endif() + if(WITH_LINKER_LLD AND _IS_LINKER_DEFAULT) + find_program(LLD_BIN "ld.lld") + mark_as_advanced(LLD_BIN) + if(NOT LLD_BIN) + message(STATUS "The \"ld.lld\" binary could not be found, using system linker.") + set(WITH_LINKER_LLD OFF) + else() + if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0) + string(APPEND CMAKE_EXE_LINKER_FLAGS " --ld-path=\"${LLD_BIN}\"") + string(APPEND CMAKE_SHARED_LINKER_FLAGS " --ld-path=\"${LLD_BIN}\"") + string(APPEND CMAKE_MODULE_LINKER_FLAGS " --ld-path=\"${LLD_BIN}\"") + else() + string(APPEND CMAKE_EXE_LINKER_FLAGS " -fuse-ld=\"${LLD_BIN}\"") + string(APPEND CMAKE_SHARED_LINKER_FLAGS " -fuse-ld=\"${LLD_BIN}\"") + string(APPEND CMAKE_MODULE_LINKER_FLAGS " -fuse-ld=\"${LLD_BIN}\"") + endif() + set(_IS_LINKER_DEFAULT OFF) + endif() + unset(LLD_BIN) + endif() + # Intel C++ Compiler elseif(CMAKE_C_COMPILER_ID MATCHES "Intel") # think these next two are broken