Merge pull request #2256 from akohlmey/cmake-use-alternate-linker
Use alternate/faster linker if available
This commit is contained in:
@ -747,6 +747,12 @@ if (${_index} GREATER -1)
|
|||||||
endif()
|
endif()
|
||||||
message(STATUS "<<< Linker flags: >>>")
|
message(STATUS "<<< Linker flags: >>>")
|
||||||
message(STATUS "Executable name: ${LAMMPS_BINARY}")
|
message(STATUS "Executable name: ${LAMMPS_BINARY}")
|
||||||
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
|
||||||
|
get_target_property(OPTIONS lammps LINK_OPTIONS)
|
||||||
|
if(OPTIONS)
|
||||||
|
message(STATUS "Linker options: ${OPTIONS}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
if(CMAKE_EXE_LINKER_FLAGS)
|
if(CMAKE_EXE_LINKER_FLAGS)
|
||||||
message(STATUS "Executable linker flags: ${CMAKE_EXE_LINKER_FLAGS}")
|
message(STATUS "Executable linker flags: ${CMAKE_EXE_LINKER_FLAGS}")
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@ -16,6 +16,33 @@ if(ENABLE_TESTING)
|
|||||||
set(MEMORYCHECK_COMMAND "${VALGRIND_BINARY}" CACHE FILEPATH "Memory Check Command")
|
set(MEMORYCHECK_COMMAND "${VALGRIND_BINARY}" CACHE FILEPATH "Memory Check Command")
|
||||||
set(MEMORYCHECK_COMMAND_OPTIONS "${VALGRIND_DEFAULT_OPTIONS}" CACHE STRING "Memory Check Command Options")
|
set(MEMORYCHECK_COMMAND_OPTIONS "${VALGRIND_DEFAULT_OPTIONS}" CACHE STRING "Memory Check Command Options")
|
||||||
|
|
||||||
|
# check if a faster linker is available.
|
||||||
|
# only verified with GNU and Clang compilers and new CMake
|
||||||
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
|
||||||
|
if((${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
|
||||||
|
OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang"))
|
||||||
|
include(CheckCXXCompilerFlag)
|
||||||
|
set(CMAKE_CUSTOM_LINKER_DEFAULT default)
|
||||||
|
check_cxx_compiler_flag(-fuse-ld=lld HAVE_LLD_LINKER)
|
||||||
|
check_cxx_compiler_flag(-fuse-ld=gold HAVE_GOLD_LINKER)
|
||||||
|
check_cxx_compiler_flag(-fuse-ld=bfd HAVE_BFD_LINKER)
|
||||||
|
if(HAVE_LLD_LINKER)
|
||||||
|
set(CMAKE_CUSTOM_LINKER_DEFAULT lld)
|
||||||
|
elseif(HAVE_GOLD_LINKER)
|
||||||
|
set(CMAKE_CUSTOM_LINKER_DEFAULT gold)
|
||||||
|
elseif(HAVE_BFD_LINKER)
|
||||||
|
set(CMAKE_CUSTOM_LINKER_DEFAULT bfd)
|
||||||
|
endif()
|
||||||
|
set(CMAKE_CUSTOM_LINKER_VALUES lld gold bfd default)
|
||||||
|
set(CMAKE_CUSTOM_LINKER ${CMAKE_CUSTOM_LINKER_DEFAULT} CACHE STRING "Choose a custom linker for faster linking (lld, gold, bfd, default)")
|
||||||
|
validate_option(CMAKE_CUSTOM_LINKER CMAKE_CUSTOM_LINKER_VALUES)
|
||||||
|
mark_as_advanced(CMAKE_CUSTOM_LINKER)
|
||||||
|
if(NOT "${CMAKE_CUSTOM_LINKER}" STREQUAL "default")
|
||||||
|
target_link_options(lammps PUBLIC -fuse-ld=${CMAKE_CUSTOM_LINKER})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
include(CTest)
|
include(CTest)
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|||||||
@ -259,6 +259,23 @@ and working.
|
|||||||
of mis-compiled code (or an undesired large loss of precision due
|
of mis-compiled code (or an undesired large loss of precision due
|
||||||
to significant reordering of operations and thus less error cancellation).
|
to significant reordering of operations and thus less error cancellation).
|
||||||
|
|
||||||
|
Use custom linker for faster link times when ENABLE_TESTING is active
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
When compiling LAMMPS with enabled tests, most test executables will
|
||||||
|
need to be linked against the LAMMPS library. Since this can be a
|
||||||
|
large with many C++ objects when many packages are enabled, link times
|
||||||
|
can become very long on machines that use the GNU BFD linker (e.g.
|
||||||
|
Linux systems). Alternatives like the ``lld`` linker of the LLVM project
|
||||||
|
or the ``gold`` linker available with GNU binutils can speed up this step
|
||||||
|
substantially. CMake will by default test if any of the two can be
|
||||||
|
enabled and use it when ``ENABLE_TESTING`` is active. It can also be
|
||||||
|
selected manually through the ``CMAKE_CUSTOM_LINKER`` CMake variable.
|
||||||
|
Allowed values are ``lld``, ``gold``, ``bfd``, or ``default``. The
|
||||||
|
``default`` option will use the system default linker otherwise, the
|
||||||
|
linker is chosen explicitly. This option is only available for the
|
||||||
|
GNU or Clang C++ compiler.
|
||||||
|
|
||||||
Tests for other components and utility functions
|
Tests for other components and utility functions
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
|||||||
@ -236,6 +236,7 @@ bilayer
|
|||||||
bilayers
|
bilayers
|
||||||
binsize
|
binsize
|
||||||
binstyle
|
binstyle
|
||||||
|
binutils
|
||||||
biomolecular
|
biomolecular
|
||||||
biomolecule
|
biomolecule
|
||||||
Biomolecules
|
Biomolecules
|
||||||
|
|||||||
Reference in New Issue
Block a user