Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable the use of LLD by default #2989

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ option(MRTRIX_STRIP_CONDA "Strip ananconda/mininconda from PATH to avoid conflic
option(MRTRIX_USE_PCH "Use precompiled headers" ON)
option(MRTRIX_PYTHON_SOFTLINK "Build directory softlink to Python source code rather than copying" ON)
option(MRTRIX_BUILD_NON_CORE_STATIC "Build MRtrix's non-core code as a static library" OFF)
option(MRTRIX_USE_LLD "Use lld as the linker" OFF)

set(MRTRIX_DEPENDENCIES_DIR "" CACHE PATH
"An optional local directory containing all thirdparty dependencies:\n \
Expand Down
44 changes: 26 additions & 18 deletions cmake/LinkerSetup.cmake
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
# On Linux we want to use the LLVM linker if available as it is faster than the default GNU linker.
# The LLVM linker is faster than the default GNU linker.
# Unfortunately, lld is not able to perform LTO when compiling with GCC.
if(MRTRIX_USE_LLD)
include(CheckCXXCompilerFlag)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_INTERPROCEDURAL_OPTIMIZATION)
set(GCC_LTO TRUE)
else()
set(GCC_LTO FALSE)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_INTERPROCEDURAL_OPTIMIZATION)
set(GCC_LTO TRUE)
message(WARNING "LLD cannot be used with GCC when LTO is enabled. Please another compiler or disable LTO.")
else()
set(GCC_LTO FALSE)
endif()

if(UNIX AND NOT APPLE AND NOT GCC_LTO)
find_program(LLVM_LINKER NAMES "ld.lld")
if(NOT GCC_LTO)
set(LINKER_FLAG "-fuse-ld=lld")
check_cxx_compiler_flag(${LINKER_FLAG} CXX_SUPPORTS_LLVM_LINKER)

if(LLVM_LINKER)
message(STATUS "Using LLVM linker: ${LLVM_LINKER}")
if(CXX_SUPPORTS_LLVM_LINKER)
find_program(LLVM_LINKER NAMES lld ld.lld)
message(STATUS "Using LLVM linker: ${LLVM_LINKER}")

if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.29)
set(CMAKE_LINKER_TYPE "LLD" CACHE STRING "Linker type")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fuse-ld=lld")
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.29)
set(CMAKE_LINKER_TYPE "LLD" CACHE STRING "Linker type")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fuse-ld=lld")
endif()
else()
message(WARNING "Compiler does not support LLVM linker. Using default linker.")
endif()
endif()

endif()
endif()

Loading