blob: 37d8bca33b6385997276780eaec971ef5391c9da (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# SPDX-FileCopyrightText: Copyright 2025 crueter
# SPDX-License-Identifier: LGPL-3.0-or-later
## FasterLinker ##
# This finds a faster linker for your compiler, if available.
# Only really tested on Linux. I would not recommend this on MSYS2.
#[[
search order:
- gold (GCC only) - the best, generally, but not packaged anymore
- mold (GCC only) - generally does well on GCC
- lld - preferred on clang
- bfd - the final fallback
- If none are found just use the default linker
]]
# This module is based on the work of Yuzu, specifically Liam White,
# and later extended by crueter.
option(USE_FASTER_LINKER "Attempt to use a faster linker program" OFF)
if (USE_FASTER_LINKER)
macro(find_linker ld)
find_program(LINKER_${ld} ld.${ld})
if (LINKER_${ld})
set(LINKER ${ld})
endif()
endmacro()
find_linker(bfd)
find_linker(lld)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
find_program(LINKER_MOLD mold)
if (LINKER_MOLD AND
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "12.1")
set(LINKER mold)
endif()
find_linker(gold)
if (LINKER STREQUAL "lld")
message(WARNING
"[FasterLinker] Using lld on GCC may cause issues.\
Install mold, gold, or disable USE_FASTER_LINKER.")
endif()
endif()
if (LINKER)
message(NOTICE "[FasterLinker] Selecting ${LINKER} as linker")
add_link_options("-fuse-ld=${LINKER}")
else()
message(WARNING "[FasterLinker] No faster linker found--using default")
endif()
endif()
|