aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarbenium <carbenium@outlook.com>2020-07-24 19:00:44 +0200
committerPeter Keresztes Schmidt <carbenium@outlook.com>2020-07-25 18:00:20 +0200
commit796e2b32e03e7b1a56e44bd4b8988f9156bbb026 (patch)
tree3a21e5e798b99a3b9ad58a192305511f64776593
parent7ea33120a03d70aaa856c2c66f183d684131746e (diff)
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.
-rw-r--r--cmake/options.cmake4
-rw-r--r--cmake/platform/unix/settings.cmake13
2 files changed, 17 insertions, 0 deletions
diff --git a/cmake/options.cmake b/cmake/options.cmake
index e57ca22fb17..0d73085b212 100644
--- a/cmake/options.cmake
+++ b/cmake/options.cmake
@@ -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()
diff --git a/cmake/platform/unix/settings.cmake b/cmake/platform/unix/settings.cmake
index 51e0955977f..e86a14944bc 100644
--- a/cmake/platform/unix/settings.cmake
+++ b/cmake/platform/unix/settings.cmake
@@ -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)