From: Matthias Maier <tamiko@43-1.org>
Date: Sun, 6 Sep 2015 21:46:50 +0000 (-0500)
Subject: CMake: Refactor check for -fuse-ld=gold into check_01_compiler_features.cmake
X-Git-Tag: v8.4.0-rc2~473^2
X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1539%2Fhead;p=dealii.git

CMake: Refactor check for -fuse-ld=gold into check_01_compiler_features.cmake
---

diff --git a/cmake/checks/check_01_compiler_features.cmake b/cmake/checks/check_01_compiler_features.cmake
index 52b885223e..d26a2f21e1 100644
--- a/cmake/checks/check_01_compiler_features.cmake
+++ b/cmake/checks/check_01_compiler_features.cmake
@@ -32,6 +32,7 @@
 #   DEAL_II_COMPILER_HAS_ATTRIBUTE_DEPRECATED
 #   DEAL_II_DEPRECATED
 #   DEAL_II_COMPILER_HAS_DIAGNOSTIC_PRAGMA
+#   DEAL_II_COMPILER_HAS_FUSE_LD_GOLD
 #
 
 
@@ -336,3 +337,26 @@ CHECK_CXX_SOURCE_COMPILES(
   DEAL_II_COMPILER_HAS_DIAGNOSTIC_PRAGMA)
 RESET_CMAKE_REQUIRED()
 
+
+#
+# Use the 'gold' linker if possible, given that it's substantially faster.
+#
+# We have to try to link a full executable with -fuse-ld=gold to check
+# whether "ld.gold" is actually available. gcc has the bad habit of
+# accepting the flag without emitting an error.
+#
+# Wolfgang Bangerth, Matthias Maier, 2015
+#
+PUSH_CMAKE_REQUIRED("-Werror")
+PUSH_CMAKE_REQUIRED("-fuse-ld=gold")
+CHECK_CXX_SOURCE_COMPILES(
+  "
+  int main() { return 0; }
+  "
+  DEAL_II_COMPILER_HAS_FUSE_LD_GOLD)
+RESET_CMAKE_REQUIRED()
+
+IF(DEAL_II_COMPILER_HAS_FUSE_LD_GOLD)
+  ADD_FLAGS(DEAL_II_LINKER_FLAGS "-fuse-ld=gold")
+ENDIF()
+
diff --git a/cmake/setup_compiler_flags_gnu.cmake b/cmake/setup_compiler_flags_gnu.cmake
index e43680ccbf..9409c36cc8 100644
--- a/cmake/setup_compiler_flags_gnu.cmake
+++ b/cmake/setup_compiler_flags_gnu.cmake
@@ -54,11 +54,6 @@ ENABLE_IF_SUPPORTED(DEAL_II_CXX_FLAGS "-fpic")
 #
 ENABLE_IF_LINKS(DEAL_II_LINKER_FLAGS "-Wl,--as-needed")
 
-#
-# Use the 'gold' linker if possible, given that it's substantially faster.
-#
-ENABLE_IF_SUPPORTED(DEAL_II_LINKER_FLAGS "-fuse-ld=gold")
-
 #
 # Setup various warnings:
 #
diff --git a/cmake/setup_compiler_flags_intel.cmake b/cmake/setup_compiler_flags_intel.cmake
index 62b3c9e6b8..2232a64d03 100644
--- a/cmake/setup_compiler_flags_intel.cmake
+++ b/cmake/setup_compiler_flags_intel.cmake
@@ -45,11 +45,6 @@ ENABLE_IF_SUPPORTED(DEAL_II_CXX_FLAGS "-fpic")
 #
 ENABLE_IF_LINKS(DEAL_II_LINKER_FLAGS "-Wl,--as-needed")
 
-#
-# Use the 'gold' linker if possible, given that it's substantially faster.
-#
-ENABLE_IF_SUPPORTED(DEAL_II_LINKER_FLAGS "-fuse-ld=gold")
-
 #
 # Set ansi mode:
 #