From 1f1767f5afbbb963d9a3de14c977ea5b5b0adc5d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 29 Jul 2020 17:36:34 -0400 Subject: [PATCH] convert linker choice to (advanced) choice. only for Clang and GNU at the moment --- cmake/Modules/Testing.cmake | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/cmake/Modules/Testing.cmake b/cmake/Modules/Testing.cmake index 3207bc4b3b..29f8b61802 100644 --- a/cmake/Modules/Testing.cmake +++ b/cmake/Modules/Testing.cmake @@ -16,15 +16,30 @@ if(ENABLE_TESTING) set(MEMORYCHECK_COMMAND "${VALGRIND_BINARY}" CACHE FILEPATH "Memory Check Command") set(MEMORYCHECK_COMMAND_OPTIONS "${VALGRIND_DEFAULT_OPTIONS}" CACHE STRING "Memory Check Command Options") - # check if a faster linker is available + # 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) - include(CheckCXXCompilerFlag) - check_cxx_compiler_flag(-fuse-ld=lld HAVE_LLD_LINKER) - check_cxx_compiler_flag(-fuse-ld=gold HAVE_GOLD_LINKER) - if(HAVE_LLD_LINKER) - target_link_options(lammps PUBLIC -fuse-ld=lld) - elseif(HAVE_GOLD_LINKER) - target_link_options(lammps PUBLIC -fuse-ld=gold) + 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()