1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-26 01:25:08 +00:00
serenity/Meta/CMake/use_linker.cmake
Daniel Bertalan dac443fbff Meta: Link Lagom with LLD by default and allow configuring the linker
This ports over the `LADYBIRD_USE_LLD` option from the standalone
Ladybird build and generalizes it to work for mold as well: the
`LAGOM_USE_LINKER` variable can be set to the desired name of the
linker. If it's empty, we default to trying LLD and Mold on ELF
platforms (in this order).
2023-09-05 14:50:36 +02:00

26 lines
952 B
CMake

# Copyright (c) 2022, Andrew Kaster <akaster@serenityos.org>
# Copyright (c) 2023, Daniel Bertalan <dani@danielbertalan.dev>
#
# SPDX-License-Identifier: BSD-2-Clause
#
if (NOT APPLE AND "${LAGOM_USE_LINKER}" STREQUAL "")
find_program(LLD_LINKER NAMES "ld.lld")
if (LLD_LINKER)
message("Using LLD to link Lagom.")
set(LAGOM_USE_LINKER "lld" CACHE STRING "")
else()
find_program(MOLD_LINKER NAMES "ld.mold")
if (MOLD_LINKER)
message("Using mold to link Lagom.")
set(LAGOM_USE_LINKER "mold" CACHE STRING "")
endif()
endif()
endif()
if (NOT "${LAGOM_USE_LINKER}" STREQUAL "")
set(LINKER_FLAG "-fuse-ld=${LAGOM_USE_LINKER}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAG}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAG}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${LINKER_FLAG}")
endif()