summaryrefslogtreecommitdiffstats
path: root/Modules/CMakeFindBinUtils.cmake
diff options
context:
space:
mode:
authorxoviat <xoviat@users.noreply.github.com>2018-01-30 19:41:16 (GMT)
committerBrad King <brad.king@kitware.com>2018-02-21 15:42:15 (GMT)
commite936b6bb5a7e930ac030645a412021383be408d7 (patch)
tree2e662d5db6d9c2489c5f347bd0daf5ee13718d58 /Modules/CMakeFindBinUtils.cmake
parent58c637643d0e26c345cb8307d51677ae3bda4f05 (diff)
downloadCMake-e936b6bb5a7e930ac030645a412021383be408d7.zip
CMake-e936b6bb5a7e930ac030645a412021383be408d7.tar.gz
CMake-e936b6bb5a7e930ac030645a412021383be408d7.tar.bz2
CMakeFindBinUtils: Find linker in PATH
Fixes: #17693
Diffstat (limited to 'Modules/CMakeFindBinUtils.cmake')
-rw-r--r--Modules/CMakeFindBinUtils.cmake19
1 files changed, 19 insertions, 0 deletions
diff --git a/Modules/CMakeFindBinUtils.cmake b/Modules/CMakeFindBinUtils.cmake
index ece0547..1b6823c 100644
--- a/Modules/CMakeFindBinUtils.cmake
+++ b/Modules/CMakeFindBinUtils.cmake
@@ -19,6 +19,25 @@
# on UNIX, cygwin and mingw
+if(CMAKE_LINKER)
+ # we only get here if CMAKE_LINKER was specified using -D or a pre-made CMakeCache.txt
+ # (e.g. via ctest) or set in CMAKE_TOOLCHAIN_FILE
+ # find the linker in the PATH if necessary
+ get_filename_component(_CMAKE_USER_LINKER_PATH "${CMAKE_LINKER}" PATH)
+ if(NOT _CMAKE_USER_LINKER_PATH)
+ find_program(CMAKE_LINKER_WITH_PATH NAMES ${CMAKE_LINKER} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
+ if(CMAKE_LINKER_WITH_PATH)
+ set(CMAKE_LINKER ${CMAKE_LINKER_WITH_PATH})
+ get_property(_CMAKE_LINKER_CACHED CACHE CMAKE_LINKER PROPERTY TYPE)
+ if(_CMAKE_LINKER_CACHED)
+ set(CMAKE_LINKER "${CMAKE_LINKER}" CACHE STRING "Default Linker" FORCE)
+ endif()
+ unset(_CMAKE_LINKER_CACHED)
+ endif()
+ unset(CMAKE_LINKER_WITH_PATH CACHE)
+ endif()
+endif()
+
# if it's the MS C/CXX compiler, search for link
if("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC"
OR "x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xMSVC"