diff --git a/cmake/modules/AddCompilerFlags.cmake b/cmake/modules/AddCompilerFlags.cmake --- a/cmake/modules/AddCompilerFlags.cmake +++ b/cmake/modules/AddCompilerFlags.cmake @@ -137,7 +137,7 @@ endif() # Save the current linker flags - set(SAVE_CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS}) + set(SAVED_CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS}) # Append the flag under test to the linker flags string(APPEND CMAKE_EXE_LINKER_FLAGS " ${FLAG}") @@ -147,7 +147,7 @@ CHECK_CXX_COMPILER_FLAG("" ${FLAG_IS_SUPPORTED}) # Restore CMAKE_EXE_LINKER_FLAGS - set(CMAKE_EXE_LINKER_FLAGS ${SAVE_CMAKE_EXE_LINKER_FLAGS}) + set(CMAKE_EXE_LINKER_FLAGS ${SAVED_CMAKE_EXE_LINKER_FLAGS}) set(${RESULT} ${${FLAG_IS_SUPPORTED}} PARENT_SCOPE) endfunction() diff --git a/contrib/debian/control b/contrib/debian/control --- a/contrib/debian/control +++ b/contrib/debian/control @@ -20,6 +20,7 @@ libqrencode-dev, libssl-dev, libzmq3-dev, + lld, ninja-build, protobuf-compiler, python3, diff --git a/contrib/gitian-descriptors/gitian-linux.yml b/contrib/gitian-descriptors/gitian-linux.yml --- a/contrib/gitian-descriptors/gitian-linux.yml +++ b/contrib/gitian-descriptors/gitian-linux.yml @@ -170,7 +170,7 @@ -DENABLE_GLIBC_BACK_COMPAT=ON \ -DCMAKE_INSTALL_PREFIX=${INSTALLPATH} \ -DCCACHE=OFF \ - -DUSE_LD_GOLD=OFF \ + -DUSE_LINKER= \ -DNETWORK_COMPATIBILITY=${CHAIN} \ ${CMAKE_EXTRA_OPTIONS[${i}]} diff --git a/contrib/utils/install-dependencies.sh b/contrib/utils/install-dependencies.sh --- a/contrib/utils/install-dependencies.sh +++ b/contrib/utils/install-dependencies.sh @@ -56,6 +56,7 @@ libtinfo5 libtool libzmq3-dev + lld make ninja-build nsis diff --git a/doc/build-unix.md b/doc/build-unix.md --- a/doc/build-unix.md +++ b/doc/build-unix.md @@ -60,7 +60,7 @@ ---------------------------------------------- Build requirements: - sudo apt-get install bsdmainutils build-essential libssl-dev libevent-dev ninja-build python3 + sudo apt-get install bsdmainutils build-essential libssl-dev libevent-dev lld ninja-build python3 **Installing cmake:** diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,7 +29,18 @@ option(START_WITH_UPNP "Make UPnP the default to map ports" OFF) option(ENABLE_CLANG_TIDY "Enable clang-tidy checks for Bitcoin ABC" OFF) option(ENABLE_PROFILING "Select the profiling tool to use" OFF) -option(USE_LD_GOLD "Try to use gold as a linker if available" ON) + +# Linker option +if(CMAKE_CROSSCOMPILING) + set(DEFAULT_LINKER "") +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set(DEFAULT_LINKER lld) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(DEFAULT_LINKER gold) +else() + set(DEFAULT_LINKER "") +endif() +set(USE_LINKER "${DEFAULT_LINKER}" CACHE STRING "Linker to be used (default: ${DEFAULT_LINKER}). Set to empty string to use the system's default.") set(OS_WITH_JEMALLOC_AS_SYSTEM_DEFAULT "Android" @@ -85,8 +96,13 @@ include(AddCompilerFlags) -if(USE_LD_GOLD) - add_linker_flags(-fuse-ld=gold) +if(USE_LINKER) + set(LINKER_FLAG "-fuse-ld=${USE_LINKER}") + check_linker_flag(IS_LINKER_SUPPORTED ${LINKER_FLAG}) + if(NOT IS_LINKER_SUPPORTED) + message(FATAL_ERROR "The ${USE_LINKER} linker is not supported, make sure ${USE_LINKER} is properly isntalled or use -DUSE_LINKER= to use the system's linker") + endif() + add_linker_flags(${LINKER_FLAG}) endif() # Prefer -g3, defaults to -g if unavailable @@ -416,7 +432,7 @@ elseif(${NETWORK_COMPATIBILITY} MATCHES "BCHN") set(NETWORK_DIR bchn) else() - message(FATAL "${NETWORK_COMPATIBILITY} is not a supported network") + message(FATAL_ERROR "${NETWORK_COMPATIBILITY} is not a supported network") endif() list(TRANSFORM