diff options
author | Austin S. Hemmelgarn <austin@netdata.cloud> | 2024-05-01 07:04:57 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-01 07:04:57 -0400 |
commit | 92c9fff172d5a4d78a9168a6792302b80dc7aaef (patch) | |
tree | 052f280db41ec2b3ff5e4943a7fa3a51427b3d6c /CMakeLists.txt | |
parent | 787cfeed1a54949e817b2a1250b640a4f5049a06 (diff) |
Detect and use ld.mold instead of the system linker. (#17534)
Not a mandatory dependency, but it significantly speeds up the final
linking step for builds.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ab193b9f1..c0b8d1f77e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,6 +86,32 @@ include(NetdataCompilerFlags) set(CMAKE_EXPORT_COMPILE_COMMANDS On) +# Check for the mold linker and try to use it if available +option(USE_MOLD "If the MOLD linker is available on the system, use it instead of the default linker." TRUE) + +if(USE_MOLD) + message(CHECK_START "Searching for MOLD linker") + find_program(MOLD_LINKER NAMES ld.mold mold) + + if(MOLD_LINKER) + execute_process(COMMAND ${MOLD_LINKER} --version + RESULT_VARIABLE MOLD_VERSION_RESULT + OUTPUT_VARIABLE MOLD_VERSION) + + if(NOT MOLD_VERSION_RESULT) + string(REPLACE "\n" "" MOLD_VERSION "${MOLD_VERSION}") + message(CHECK_PASS "found (version: ${MOLD_VERSION})") + message(STATUS "Using mold instead of the system default for linking.") + add_compile_options("-fuse-ld=mold") + add_link_options("-fuse-ld=mold") + else() + message(CHECK_FAIL "failed") + endif() + else() + message(CHECK_FAIL "failed") + endif() +endif() + set(CONFIG_H_DIR ${CMAKE_BINARY_DIR}) set(CONFIG_H ${CONFIG_H_DIR}/config.h) |