From 5126e6ea612b2b7fe2e5ec23bae1a62dc596454a Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Tue, 1 Oct 2019 14:31:39 -0400 Subject: [PATCH] cmake: use gold linker if available --- CMakeLists.txt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6169446bcc..da3f1d1d67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -208,6 +208,25 @@ endif() #============================================================================= +# gold linker - use if available +include(CMakeDependentOption) +CMAKE_DEPENDENT_OPTION(USE_LD_GOLD + "Use GNU gold linker" ON + "NOT WIN32;NOT APPLE" OFF +) + +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") + else() + set(USE_LD_GOLD OFF) + endif() +endif() + +#============================================================================= + # Setup install paths if (${PX4_PLATFORM} STREQUAL "posix")