build: use lld or mold linkers in supported platforms

This commit is contained in:
Gabriel Ferreira
2022-09-20 17:08:57 -03:00
parent d4cf96cfd0
commit 8d96d482b6
2 changed files with 114 additions and 0 deletions

View File

@@ -234,6 +234,36 @@ if(${CLANG} AND APPLE)
set(STATIC_LINK_FLAGS)
endif()
# Search for faster linkers mold and lld, and use them if available
mark_as_advanced(MOLD LLD)
find_program(MOLD mold)
find_program(LLD ld.lld)
# USING_FAST_LINKER will be defined if a fast linker is being used and its
# content will correspond to the fast linker name
# Mold support was added in GCC 12.1.0
if(NOT USING_FAST_LINKER
AND NOT (${MOLD} STREQUAL "MOLD-NOTFOUND")
AND LINUX
AND ${GCC}
AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12.1.0)
)
set(USING_FAST_LINKER MOLD)
add_link_options("-fuse-ld=mold")
endif()
if(NOT USING_FAST_LINKER AND NOT (${LLD} STREQUAL "LLD-NOTFOUND")
AND (${GCC} OR ${CLANG})
)
set(USING_FAST_LINKER LLD)
add_link_options("-fuse-ld=lld")
if(WIN32)
# Clear unsupported linker flags on Windows
set(LIB_AS_NEEDED_PRE)
endif()
endif()
# Include CMake files used for compiler checks
include(CheckIncludeFile) # Used to check a single C header at a time
include(CheckIncludeFileCXX) # Used to check a single C++ header at a time