Skip to content

Commit

Permalink
Support mold linker (#5331)
Browse files Browse the repository at this point in the history
  • Loading branch information
yixinglu committed Feb 10, 2023
1 parent 6bc7c1f commit d0b1464
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions cmake/ClangTidy.cmake
@@ -1,3 +1,8 @@
# Copyright (c) 2020 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License.
#

if (ENABLE_CLANG_TIDY)
if (${CMAKE_VERSION} VERSION_LESS "3.6.0")
message(FATAL_ERROR "clang-tidy requires CMake version at least 3.6.")
Expand Down
18 changes: 18 additions & 0 deletions cmake/FindMoldLinker.cmake
@@ -0,0 +1,18 @@
# Copyright (c) 2023 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License.
#

find_program (MOLD NAMES "mold")
if (NOT MOLD)
message(FATAL_ERROR "Could not find the mold linker")
endif()

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.1.0)
get_filename_component(MOLD_PATH ${MOLD} DIRECTORY)
nebula_add_exe_linker_flag(-B${MOLD_PATH}/../libexec/mold)
nebula_add_shared_linker_flag(-B${MOLD_PATH}/../libexec/mold)
else()
nebula_add_exe_linker_flag(-fuse-ld=mold)
nebula_add_shared_linker_flag(-fuse-ld=mold)
endif()
11 changes: 8 additions & 3 deletions cmake/nebula/LinkerConfig.cmake
@@ -1,7 +1,7 @@
set(NEBULA_USE_LINKER
"bfd"
CACHE STRING "Linker to be used")
set(USER_LINKER_OPTION_VALUES "lld" "gold" "bfd")
set(USER_LINKER_OPTION_VALUES "lld" "gold" "bfd" "mold")
set_property(CACHE NEBULA_USE_LINKER PROPERTY STRINGS ${USER_LINKER_OPTION_VALUES})
list(
FIND
Expand All @@ -17,8 +17,13 @@ endif()

print_config(NEBULA_USE_LINKER)

nebula_add_exe_linker_flag(-fuse-ld=${NEBULA_USE_LINKER})
nebula_add_shared_linker_flag(-fuse-ld=${NEBULA_USE_LINKER})
if (${NEBULA_USE_LINKER} STREQUAL "mold")
include(FindMoldLinker)
else()
nebula_add_exe_linker_flag(-fuse-ld=${NEBULA_USE_LINKER})
nebula_add_shared_linker_flag(-fuse-ld=${NEBULA_USE_LINKER})
endif()

nebula_add_exe_linker_flag(-static-libstdc++)
nebula_add_exe_linker_flag(-static-libgcc)
nebula_add_exe_linker_flag(-no-pie)
Expand Down

0 comments on commit d0b1464

Please sign in to comment.