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>
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)