]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: add WITH_MOLD option for Mold linker support 69711/head
authorRonen Friedman <rfriedma@redhat.com>
Sun, 28 Jun 2026 14:42:23 +0000 (14:42 +0000)
committerRonen Friedman <rfriedma@redhat.com>
Sun, 28 Jun 2026 14:53:54 +0000 (14:53 +0000)
Add a WITH_MOLD cmake option that auto-configures the build for
the Mold linker. When enabled, cmake finds mold, sets CMAKE_LINKER,
injects -fuse-ld=mold into all linker flag variables, and sets
USING_MOLD_LINKER which gates the Mold-specific workarounds added
in the previous commit.

Usage: cmake -DWITH_MOLD=ON ...

Assisted-by: Claude <claude.ai>
Signed-off-by: Ronen Friedman <rfriedma@redhat.com>
CMakeLists.txt

index c02a5021ccc1d4a715b042e10eb9c7bf366e7db8..b173c638cd04e4bb41d8a3e5b253f0183f312d6c 100644 (file)
@@ -75,6 +75,20 @@ if(MINGW)
   link_directories(${MINGW_LINK_DIRECTORIES})
 endif()
 
+option(WITH_MOLD "Use the Mold linker" OFF)
+if(WITH_MOLD)
+  find_program(_mold_path mold REQUIRED)
+  message(STATUS "Mold linker: ${_mold_path}")
+  set(CMAKE_LINKER ${_mold_path} CACHE FILEPATH "Linker" FORCE)
+  set(MOLD_FUSE_LD_FLAG "-fuse-ld=mold" CACHE INTERNAL "")
+  foreach(_flags CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS)
+    if(NOT "${${_flags}}" MATCHES "fuse-ld=")
+      string(APPEND ${_flags} " ${MOLD_FUSE_LD_FLAG}")
+    endif()
+  endforeach()
+  set(USING_MOLD_LINKER TRUE CACHE INTERNAL "")
+endif()
+
 option(WITH_CCACHE "Build with ccache.")
 if(WITH_CCACHE)
   if(CMAKE_C_COMPILER_LAUNCHER OR CMAKE_CXX_COMPILER_LAUNCHER)