From edb8b0aeb788fd2b892c0fb9e3f7f5bae7b0f7e4 Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Mon, 8 Jan 2024 14:40:56 +0100 Subject: [PATCH] CMake: Add QTC_USE_LLVM_LINKER option llvm-link is faster on macOS than ld64. llvm-link can also be used with MinGW GCC's ld which is very slow in debug mode. Change-Id: Ie519f3111e05cfc7dffab2676108a0d53ebe08b2 Reviewed-by: Reviewed-by: Marcus Tillmanns --- CMakeLists.txt | 1 + cmake/QtCreatorAPI.cmake | 1 + cmake/QtCreatorAPIInternal.cmake | 9 +++++++++ 3 files changed, 11 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index acab23d9641..2aefb1a58dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) qtc_handle_compiler_cache_support() +qtc_handle_llvm_linker() option(BUILD_LINK_WITH_QT "Link with Qt from the parent Qt Creator" OFF) qtc_link_with_qt() diff --git a/cmake/QtCreatorAPI.cmake b/cmake/QtCreatorAPI.cmake index 66d9407787c..5cbd9cd4bf4 100644 --- a/cmake/QtCreatorAPI.cmake +++ b/cmake/QtCreatorAPI.cmake @@ -46,6 +46,7 @@ option(QTC_SEPARATE_DEBUG_INFO "Extract debug information from binary files." OF option(WITH_SCCACHE_SUPPORT "Enables support for building with SCCACHE and separate debug info with MSVC, which SCCACHE normally doesn't support." OFF) option(WITH_CCACHE_SUPPORT "Enables support for building with CCACHE and separate debug info with MSVC, which CCACHE normally doesn't support." "${ENV_WITH_CCACHE_SUPPORT}") option(QTC_STATIC_BUILD "Builds libraries and plugins as static libraries" OFF) +option(QTC_USE_LLVM_LINKER "Uses llvm-link linker if found." OFF) # If we provide a list of plugins, executables, libraries, then the BUILD__BY_DEFAULT will be set to OFF # and for every element we set BUILD__ to ON diff --git a/cmake/QtCreatorAPIInternal.cmake b/cmake/QtCreatorAPIInternal.cmake index 95fb83207d4..9a6f06b73e0 100644 --- a/cmake/QtCreatorAPIInternal.cmake +++ b/cmake/QtCreatorAPIInternal.cmake @@ -141,6 +141,15 @@ function(qtc_handle_compiler_cache_support) endif() endfunction() +function(qtc_handle_llvm_linker) + if (QTC_USE_LLVM_LINKER) + find_program(LLVM_LINK_PROGRAM llvm-link) + if(LLVM_LINK_PROGRAM) + set(CMAKE_LINKER "${LLVM_LINK_PROGRAM}" CACHE STRING "LLVM linker" FORCE) + endif() + endif() +endfunction() + function(qtc_link_with_qt) # When building with Qt Creator 4.15+ do the "Link with Qt..." automatically if (BUILD_LINK_WITH_QT AND DEFINED CMAKE_PROJECT_INCLUDE_BEFORE)