-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2989 from MRtrix3/mrtrix_use_lld_option
Disable the use of LLD by default
- Loading branch information
Showing
2 changed files
with
27 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|