Build: Add WITH_LD_GOLD option to use gold linker on unix

gold is an ELF-only linker which has a better performance
than the default ld.
This commit is contained in:
Carbenium
2020-07-24 19:00:44 +02:00
committed by Peter Keresztes Schmidt
parent 7ea33120a0
commit 796e2b32e0
2 changed files with 17 additions and 0 deletions

View File

@@ -55,3 +55,7 @@ set(WITH_SOURCE_TREE "hierarchical" CACHE STRING "Build the source tree for I
set_property(CACHE WITH_SOURCE_TREE PROPERTY STRINGS no flat hierarchical hierarchical-folders)
option(WITHOUT_GIT "Disable the GIT testing routines" 0)
option(BUILD_TESTING "Build test suite" 0)
if(UNIX)
option(USE_LD_GOLD "Use GNU gold linker" 0)
endif()

View File

@@ -18,6 +18,19 @@ add_custom_target(uninstall
)
message(STATUS "UNIX: Created uninstall target")
if(USE_LD_GOLD)
execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
if("${LD_VERSION}" MATCHES "GNU gold")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold")
message(STATUS "UNIX: Using GNU gold linker")
else()
message(WARNING "UNIX: GNU gold linker isn't available, using the default system linker")
endif()
else()
message(STATUS "UNIX: Using default system linker")
endif()
message(STATUS "UNIX: Detected compiler: ${CMAKE_C_COMPILER}")
if(CMAKE_C_COMPILER MATCHES "gcc" OR CMAKE_C_COMPILER_ID STREQUAL "GNU")
include(${CMAKE_SOURCE_DIR}/cmake/compiler/gcc/settings.cmake)