New-Cli-Installer/cmake/Linker.cmake

34 lines
972 B
CMake
Raw Normal View History

2021-12-01 20:37:18 +08:00
option(ENABLE_USER_LINKER "Enable a specific linker if available" OFF)
include(CheckCXXCompilerFlag)
set(USER_LINKER_OPTION
"lld"
CACHE STRING "Linker to be used")
2022-01-03 05:45:54 +08:00
set(USER_LINKER_OPTION_VALUES "lld" "gold" "bfd" "mold")
2021-12-01 20:37:18 +08:00
set_property(CACHE USER_LINKER_OPTION PROPERTY STRINGS ${USER_LINKER_OPTION_VALUES})
list(
FIND
USER_LINKER_OPTION_VALUES
${USER_LINKER_OPTION}
USER_LINKER_OPTION_INDEX)
if(${USER_LINKER_OPTION_INDEX} EQUAL -1)
message(
STATUS
"Using custom linker: '${USER_LINKER_OPTION}', explicitly supported entries are ${USER_LINKER_OPTION_VALUES}")
endif()
function(configure_linker project_name)
if(NOT ENABLE_USER_LINKER)
return()
endif()
set(LINKER_FLAG "-fuse-ld=${USER_LINKER_OPTION}")
check_cxx_compiler_flag(${LINKER_FLAG} CXX_SUPPORTS_USER_LINKER)
if(CXX_SUPPORTS_USER_LINKER)
target_compile_options(${project_name} INTERFACE ${LINKER_FLAG})
endif()
endfunction()