chore: simplify USE_ALTERNATE_LINKER code (#6692)
This commit is contained in:
@@ -73,6 +73,7 @@
|
||||
- Dev: Disabled `llvm-prefer-static-over-anonymous-namespace` in clang-tidy. (#6610)
|
||||
- Dev: Added Clazy linting in CI. (#6623)
|
||||
- Dev: Added custom clang-tidy module linting in CI. (#6626)
|
||||
- Dev: CMake option `USE_ALTERNATE_LINKER` now errors if the given linker can't be found. (#6692)
|
||||
- Dev: Moved Twitch PubSub to liveupdates. (#6638)
|
||||
|
||||
## 2.5.4
|
||||
|
||||
+7
-14
@@ -1,4 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
# CMake upgrade notes:
|
||||
# - In CMake >= 3.29, we should deprecate USE_ALTERNATE_LINKER in favour of CMake's CMAKE_LINKER_TYPE
|
||||
set(CMAKE_EXPORT_NO_PACKAGE_REGISTRY On) # For rapidjson
|
||||
cmake_policy(SET CMP0087 NEW) # evaluates generator expressions in `install(CODE/SCRIPT)`
|
||||
cmake_policy(SET CMP0091 NEW) # select MSVC runtime library through `CMAKE_MSVC_RUNTIME_LIBRARY`
|
||||
@@ -37,6 +39,8 @@ add_feature_info("Chatterino code sanitizer support" CHATTERINO_SANITIZER_SUPPOR
|
||||
option(CHATTERINO_UPDATER "Enable update checks" ON)
|
||||
mark_as_advanced(CHATTERINO_UPDATER)
|
||||
|
||||
set(USE_ALTERNATE_LINKER "" CACHE STRING "Use alternate linker. Leave empty for system default. CMake 3.29 users can use CMAKE_LINKER_TYPE instead.")
|
||||
|
||||
if(CHATTERINO_SANITIZER_SUPPORT)
|
||||
list(APPEND CMAKE_MODULE_PATH
|
||||
"${CMAKE_SOURCE_DIR}/cmake/sanitizers-cmake/cmake"
|
||||
@@ -90,25 +94,14 @@ elseif (CCACHE_PROGRAM)
|
||||
set(_compiler_launcher ${CCACHE_PROGRAM})
|
||||
endif ()
|
||||
|
||||
|
||||
# Alternate linker code taken from heavyai/heavydb
|
||||
# https://github.com/heavyai/heavydb/blob/0517d99b467806f6af7b4c969e351368a667497d/CMakeLists.txt#L87-L103
|
||||
macro(set_alternate_linker linker)
|
||||
if(USE_ALTERNATE_LINKER)
|
||||
find_program(LINKER_EXECUTABLE ld.${USE_ALTERNATE_LINKER} ${USE_ALTERNATE_LINKER})
|
||||
if(LINKER_EXECUTABLE)
|
||||
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 12.0.0)
|
||||
add_link_options("-ld-path=${USE_ALTERNATE_LINKER}")
|
||||
else()
|
||||
message(STATUS "Using alternate linker '${USE_ALTERNATE_LINKER}'")
|
||||
add_link_options("-fuse-ld=${USE_ALTERNATE_LINKER}")
|
||||
endif()
|
||||
else()
|
||||
set(USE_ALTERNATE_LINKER "" CACHE STRING "Use alternate linker" FORCE)
|
||||
message(FATAL_ERROR "Alternate linker ${USE_ALTERNATE_LINKER} could not be found under ld.${USE_ALTERNATIVE_LINKER} or ${USE_ALTERNATE_LINKER}")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
set(USE_ALTERNATE_LINKER "" CACHE STRING "Use alternate linker. Leave empty for system default; alternatives are 'gold', 'lld', 'bfd', 'mold'")
|
||||
if(NOT "${USE_ALTERNATE_LINKER}" STREQUAL "")
|
||||
set_alternate_linker(${USE_ALTERNATE_LINKER})
|
||||
endif()
|
||||
|
||||
if (_compiler_launcher)
|
||||
|
||||
Reference in New Issue
Block a user