summaryrefslogtreecommitdiffstats
path: root/Modules/CMakeFindBinUtils.cmake
diff options
context:
space:
mode:
authorMateusz Zych <mte.zych@gmail.com>2018-10-25 00:34:26 (GMT)
committerBrad King <brad.king@kitware.com>2018-10-29 17:40:47 (GMT)
commitbd9bfc644954a48b1bf7ea18fc260a1231840671 (patch)
tree983bc115307da95ae78550b515d26ae324274359 /Modules/CMakeFindBinUtils.cmake
parent0033676796748bd8fe00f3f96d3470405cdb94fe (diff)
downloadCMake-bd9bfc644954a48b1bf7ea18fc260a1231840671.zip
CMake-bd9bfc644954a48b1bf7ea18fc260a1231840671.tar.gz
CMake-bd9bfc644954a48b1bf7ea18fc260a1231840671.tar.bz2
MSVC: Respect CMAKE_RC_COMPILER and CMAKE_MT in vs_link_{dll,exe}
CMake commands vs_link_dll and vs_link_exe, performing linking on MSVC, are responsible for calling resource compiler and manifest tool. Before this commit, both of these tools were called directly, with the expectation that they are available in the `PATH`. This has been fixed by respecting CMake variables `CMAKE_RC_COMPILER` and `CMAKE_MT` defining paths to these tools. Fixes: #17804
Diffstat (limited to 'Modules/CMakeFindBinUtils.cmake')
-rw-r--r--Modules/CMakeFindBinUtils.cmake52
1 files changed, 36 insertions, 16 deletions
diff --git a/Modules/CMakeFindBinUtils.cmake b/Modules/CMakeFindBinUtils.cmake
index b805fa7..35f75c9 100644
--- a/Modules/CMakeFindBinUtils.cmake
+++ b/Modules/CMakeFindBinUtils.cmake
@@ -14,29 +14,48 @@
# CMAKE_AR
# CMAKE_RANLIB
# CMAKE_LINKER
+# CMAKE_MT
# CMAKE_STRIP
# CMAKE_INSTALL_NAME_TOOL
# 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)
+# Resolve full path of CMAKE_TOOL from user-defined name and SEARCH_PATH.
+function(__resolve_tool_path CMAKE_TOOL SEARCH_PATH DOCSTRING)
+
+ if(${CMAKE_TOOL})
+ # We only get here if CMAKE_TOOL was
+ # specified using -D or a pre-made CMakeCache.txt (e.g. via ctest)
+ # or set in CMAKE_TOOLCHAIN_FILE.
+
+ get_filename_component(_CMAKE_USER_TOOL_PATH "${${CMAKE_TOOL}}" DIRECTORY)
+ # Is CMAKE_TOOL a user-defined name instead of a full path?
+ if(NOT _CMAKE_USER_TOOL_PATH)
+
+ # Find CMAKE_TOOL in the SEARCH_PATH directory by user-defined name.
+ find_program(_CMAKE_TOOL_WITH_PATH NAMES ${${CMAKE_TOOL}} HINTS ${SEARCH_PATH})
+ if(_CMAKE_TOOL_WITH_PATH)
+
+ # Overwrite CMAKE_TOOL with full path found in SEARCH_PATH.
+ set(${CMAKE_TOOL} ${_CMAKE_TOOL_WITH_PATH} PARENT_SCOPE)
+
+ get_property(_CMAKE_TOOL_CACHED CACHE ${CMAKE_TOOL} PROPERTY TYPE)
+ # If CMAKE_TOOL is present in the CMake Cache, then overwrit it as well.
+ if(_CMAKE_TOOL_CACHED)
+ set(${CMAKE_TOOL} "${_CMAKE_TOOL_WITH_PATH}" CACHE STRING ${DOCSTRING} FORCE)
+ endif()
+
endif()
- unset(_CMAKE_LINKER_CACHED)
+ unset(_CMAKE_TOOL_WITH_PATH CACHE)
+
endif()
- unset(CMAKE_LINKER_WITH_PATH CACHE)
+
endif()
-endif()
+
+endfunction()
+
+__resolve_tool_path(CMAKE_LINKER "${_CMAKE_TOOLCHAIN_LOCATION}" "Default Linker")
+__resolve_tool_path(CMAKE_MT "${_CMAKE_TOOLCHAIN_LOCATION}" "Default Manifest Tool")
set(_CMAKE_TOOL_VARS "")
@@ -49,8 +68,9 @@ if("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC"
AND NOT CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android"))
find_program(CMAKE_LINKER NAMES link HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
+ find_program(CMAKE_MT NAMES mt HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
- list(APPEND _CMAKE_TOOL_VARS CMAKE_LINKER)
+ list(APPEND _CMAKE_TOOL_VARS CMAKE_LINKER CMAKE_MT)
# in all other cases search for ar, ranlib, etc.
else()