From 8b3d798374a2c6b5026791e8ef5ce4fe6494f801 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 12 Jan 2022 13:35:07 +1100 Subject: CMake: add WITH_LINKER_MOLD option for GCC/Clang Unix platforms Can give considerably faster linking, especially on system with many cores. The mold linker recently reached 1.0, see: https://github.com/rui314/mold The current stable release of GCC can't use this linker via -fuse-ld=mold, so this patch uses the "-B" argument to add a binary directory containing an alternate "ld" command that points to "mold" (which is part of the default mold installation). Some timing tests for linking full builds for AMD TR 3970X: - BFD: 20.78 seconds. - LLD: 12.16 seconds. - GOLD: 7.21 seconds. - MOLD: 2.53 seconds. Ref D13807 Reviewed by: sergey, brecht --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index 88c71899f8e..5d796a5c140 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -567,6 +567,10 @@ if(UNIX AND NOT APPLE) option(WITH_LINKER_LLD "Use ld.lld linker which is usually faster than ld.gold" OFF) mark_as_advanced(WITH_LINKER_LLD) endif() + if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") + option(WITH_LINKER_MOLD "Use ld.mold linker which is usually faster than ld.gold & ld.lld." OFF) + mark_as_advanced(WITH_LINKER_MOLD) + endif() endif() option(WITH_COMPILER_ASAN "Build and link against address sanitizer (only for Debug & RelWithDebInfo targets)." OFF) -- cgit v1.2.3