From: Ronen Friedman Date: Sun, 28 Jun 2026 14:42:23 +0000 (+0000) Subject: cmake: add WITH_MOLD option for Mold linker support X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ebc18499afd52ff43614cbf3c1f10c4713707d0f;p=ceph.git cmake: add WITH_MOLD option for Mold linker support 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 Signed-off-by: Ronen Friedman --- diff --git a/CMakeLists.txt b/CMakeLists.txt index c02a5021ccc..b173c638cd0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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)