cmake: Use ld.gold if available for faster link times. (#3738)
authorMathias Preiner <mathias.preiner@gmail.com>
Mon, 10 Feb 2020 19:34:11 +0000 (11:34 -0800)
committerGitHub <noreply@github.com>
Mon, 10 Feb 2020 19:34:11 +0000 (11:34 -0800)
CMakeLists.txt

index 1c187eff3dbc21bb1575619356209768ab686dff..e5d0cf0e5e231a2b3895632e94e039430d5c46bc 100644 (file)
@@ -240,6 +240,19 @@ add_check_c_cxx_flag("-Wimplicit-fallthrough")
 # cdlist.h warnings. Remove when fixed.
 add_check_cxx_flag("-Wno-class-memaccess")
 
+#-----------------------------------------------------------------------------#
+# Use ld.gold if available
+
+execute_process(COMMAND ${CMAKE_C_COMPILER}
+                -fuse-ld=gold
+                -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
+if ("${LD_VERSION}" MATCHES "GNU gold")
+  string(APPEND CMAKE_EXE_LINKER_FLAGS " -fuse-ld=gold")
+  string(APPEND CMAKE_SHARED_LINKER_FLAGS " -fuse-ld=gold")
+  string(APPEND CMAKE_MODULE_LINKER_FLAGS " -fuse-ld=gold")
+  message(STATUS "Using GNU gold linker.")
+endif ()
+
 #-----------------------------------------------------------------------------#
 # Option defaults (three-valued options (cvc4_option(...)))
 #