diff options
Diffstat (limited to 'Modules/CMakeFindBinUtils.cmake')
-rw-r--r-- | Modules/CMakeFindBinUtils.cmake | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/Modules/CMakeFindBinUtils.cmake b/Modules/CMakeFindBinUtils.cmake index 830639d..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 "") @@ -44,12 +63,14 @@ set(_CMAKE_TOOL_VARS "") if("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC" OR "x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xMSVC" OR (CMAKE_HOST_WIN32 AND "x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xPGI") + OR (CMAKE_HOST_WIN32 AND "x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xNVIDIA") OR (CMAKE_GENERATOR MATCHES "Visual Studio" 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() |