]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add support for the mold linker
authorDaniel Arndt <arndtd@ornl.gov>
Fri, 2 Dec 2022 19:33:38 +0000 (14:33 -0500)
committerDaniel Arndt <arndtd@ornl.gov>
Fri, 2 Dec 2022 19:41:19 +0000 (14:41 -0500)
cmake/checks/check_02_compiler_features.cmake

index c3a112afe55a3737fe6627aebb7d0cab5f9201bb..d2130d3a18386ecb710676eab8fc0edc4993bdd9 100644 (file)
@@ -330,11 +330,12 @@ reset_cmake_required()
 
 
 #
-# Use 'lld' or the 'gold' linker if possible, given that either of them is
-# substantially faster.
+# Use 'mold', 'lld' or the 'gold' linker if possible, given that either of them
+# is substantially faster.
 #
-# We have to try to link a full executable with -fuse-ld=lld or -fuse-ld=gold
-# to check whether "ld.lld" or "ld.gold" is actually available.
+# We have to try to link a full executable with -fuse-ld=mold, -fuse-ld=lld or
+# -fuse-ld=gold to check whether "ld.mold", "ld.lld" or "ld.gold" is actually
+# available.
 #
 # Clang always reports "argument unused during compilation", but fails at link
 # time for an unsupported linker.
@@ -368,8 +369,17 @@ if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
   add_flags(CMAKE_REQUIRED_FLAGS "-fPIC")
 
   #
-  # Check for ld.lld and ld.gold support:
+  # Check for ld.mold, ld.lld and ld.gold support:
   #
+  add_flags(CMAKE_REQUIRED_FLAGS "-fuse-ld=mold")
+  CHECK_CXX_SOURCE_COMPILES(
+    "
+    #include <iostream>
+    void foo() { std::cout << \"Hello, world!\" << std::endl; }
+    "
+    DEAL_II_COMPILER_HAS_FUSE_LD_MOLD)
+
+  strip_flag(CMAKE_REQUIRED_FLAGS "-fuse-ld=mold")
   add_flags(CMAKE_REQUIRED_FLAGS "-fuse-ld=lld")
   CHECK_CXX_SOURCE_COMPILES(
     "
@@ -387,7 +397,9 @@ if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
     "
     DEAL_II_COMPILER_HAS_FUSE_LD_GOLD)
 
-  if(DEAL_II_COMPILER_HAS_FUSE_LD_LLD)
+  if(DEAL_II_COMPILER_HAS_FUSE_LD_MOLD)
+    add_flags(DEAL_II_LINKER_FLAGS "-fuse-ld=mold")
+  elseif(DEAL_II_COMPILER_HAS_FUSE_LD_LLD)
     add_flags(DEAL_II_LINKER_FLAGS "-fuse-ld=lld")
   elseif(DEAL_II_COMPILER_HAS_FUSE_LD_GOLD)
     add_flags(DEAL_II_LINKER_FLAGS "-fuse-ld=gold")

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.