Commit b12aec6c authored by Thomas Bernard's avatar Thomas Bernard Committed by Brad King
Browse files

BinUtils: prefer bin utils matching the compiler version extension

parent 06dfa5a7
......@@ -161,9 +161,10 @@ if (NOT _CMAKE_TOOLCHAIN_PREFIX)
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang|QCC")
get_filename_component(COMPILER_BASENAME "${CMAKE_C_COMPILER}" NAME)
if (COMPILER_BASENAME MATCHES "^(.+-)(clang|g?cc)(-[0-9]+(\\.[0-9]+)*)?(-[^.]+)?(\\.exe)?$")
if (COMPILER_BASENAME MATCHES "^(.+-)?(clang|g?cc)(-cl)?(-[0-9]+(\\.[0-9]+)*)?(-[^.]+)?(\\.exe)?$")
set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
set(_CMAKE_COMPILER_SUFFIX ${CMAKE_MATCH_5})
set(_CMAKE_TOOLCHAIN_SUFFIX ${CMAKE_MATCH_4})
set(_CMAKE_COMPILER_SUFFIX ${CMAKE_MATCH_6})
elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
if(CMAKE_C_COMPILER_TARGET)
set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_C_COMPILER_TARGET}-)
......
......@@ -160,8 +160,9 @@ if (NOT _CMAKE_TOOLCHAIN_PREFIX)
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang|QCC")
get_filename_component(COMPILER_BASENAME "${CMAKE_CXX_COMPILER}" NAME)
if (COMPILER_BASENAME MATCHES "^(.+-)(clan)?[gc]\\+\\+(-[0-9]+(\\.[0-9]+)*)?(-[^.]+)?(\\.exe)?$")
if (COMPILER_BASENAME MATCHES "^(.+-)?(clang\\+\\+|g\\+\\+|clang-cl)(-[0-9]+(\\.[0-9]+)*)?(-[^.]+)?(\\.exe)?$")
set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
set(_CMAKE_TOOLCHAIN_SUFFIX ${CMAKE_MATCH_3})
set(_CMAKE_COMPILER_SUFFIX ${CMAKE_MATCH_5})
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
if(CMAKE_CXX_COMPILER_TARGET)
......
......@@ -70,17 +70,18 @@ if(("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC" AND
OR (CMAKE_GENERATOR MATCHES "Visual Studio"
AND NOT CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android"))
set(_CMAKE_LINKER_NAMES "link")
set(_CMAKE_AR_NAMES "lib")
set(_CMAKE_MT_NAMES "mt")
if("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xClang")
find_program(CMAKE_NM NAMES ${_CMAKE_TOOLCHAIN_PREFIX}nm llvm-nm HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
set(_CMAKE_ADDITIONAL_LINKER_NAMES "lld-link")
set(_CMAKE_ADDITIONAL_AR_NAMES "llvm-lib")
set(_CMAKE_NM_NAMES "llvm-nm" "nm")
list(APPEND _CMAKE_AR_NAMES "lib" "llvm-lib")
list(APPEND _CMAKE_MT_NAMES "mt" "llvm-mt")
list(APPEND _CMAKE_LINKER_NAMES "lld-link")
list(APPEND _CMAKE_TOOL_VARS NM)
endif()
find_program(CMAKE_LINKER NAMES ${_CMAKE_ADDITIONAL_LINKER_NAMES} link HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
find_program(CMAKE_AR NAMES ${_CMAKE_ADDITIONAL_AR_NAMES} lib HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
find_program(CMAKE_MT NAMES mt HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
list(APPEND _CMAKE_TOOL_VARS LINKER MT)
list(APPEND _CMAKE_TOOL_VARS LINKER MT AR)
# in all other cases search for ar, ranlib, etc.
else()
......@@ -92,55 +93,54 @@ else()
endif()
if("${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL Clang)
set(_CMAKE_ADDITIONAL_AR_NAMES "llvm-ar")
set(_CMAKE_ADDITIONAL_RANLIB_NAMES "llvm-ranlib")
set(_CMAKE_ADDITIONAL_STRIP_NAMES "llvm-strip")
if("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC")
set(_CMAKE_ADDITIONAL_LINKER_NAMES "lld-link")
set(_CMAKE_LINKER_NAMES "lld-link")
else()
set(_CMAKE_ADDITIONAL_LINKER_NAMES "ld.lld")
set(_CMAKE_LINKER_NAMES "ld.lld")
endif()
set(_CMAKE_ADDITIONAL_NM_NAMES "llvm-nm")
set(_CMAKE_ADDITIONAL_OBJDUMP_NAMES "llvm-objdump")
set(_CMAKE_ADDITIONAL_OBJCOPY_NAMES "llvm-objcopy")
set(_CMAKE_ADDITIONAL_READELF_NAMES "llvm-readelf")
set(_CMAKE_ADDITIONAL_DLLTOOL_NAMES "llvm-dlltool")
set(_CMAKE_ADDITIONAL_ADDR2LINE_NAMES "llvm-addr2line")
list(APPEND _CMAKE_AR_NAMES "llvm-ar")
list(APPEND _CMAKE_NM_NAMES "llvm-nm")
list(APPEND _CMAKE_OBJDUMP_NAMES "llvm-objdump")
list(APPEND _CMAKE_OBJCOPY_NAMES "llvm-objcopy")
list(APPEND _CMAKE_READELF_NAMES "llvm-readelf")
list(APPEND _CMAKE_DLLTOOL_NAMES "llvm-dlltool")
list(APPEND _CMAKE_ADDR2LINE_NAMES "llvm-addr2line")
endif()
if(NOT CMAKE_CROSSCOMPILING AND NOT "${_CMAKE_TOOLCHAIN_PREFIX}" STREQUAL "")
list(APPEND _CMAKE_ADDITIONAL_AR_NAMES "ar")
list(APPEND _CMAKE_ADDITIONAL_RANLIB_NAMES "ranlib")
list(APPEND _CMAKE_ADDITIONAL_STRIP_NAMES "strip")
list(APPEND _CMAKE_ADDITIONAL_LINKER_NAMES "ld")
list(APPEND _CMAKE_ADDITIONAL_NM_NAMES "nm")
list(APPEND _CMAKE_ADDITIONAL_OBJDUMP_NAMES "objdump")
list(APPEND _CMAKE_ADDITIONAL_OBJCOPY_NAMES "objcopy")
list(APPEND _CMAKE_ADDITIONAL_READELF_NAMES "readelf")
list(APPEND _CMAKE_ADDITIONAL_DLLTOOL_NAMES "dlltool")
list(APPEND _CMAKE_ADDITIONAL_ADDR2LINE_NAMES "addr2line")
endif()
list(APPEND _CMAKE_AR_NAMES "ar")
list(APPEND _CMAKE_RANLIB_NAMES "ranlib")
list(APPEND _CMAKE_STRIP_NAMES "strip")
list(APPEND _CMAKE_LINKER_NAMES "ld")
list(APPEND _CMAKE_NM_NAMES "nm")
list(APPEND _CMAKE_OBJDUMP_NAMES "objdump")
list(APPEND _CMAKE_OBJCOPY_NAMES "objcopy")
list(APPEND _CMAKE_READELF_NAMES "readelf")
list(APPEND _CMAKE_DLLTOOL_NAMES "dlltool")
list(APPEND _CMAKE_ADDR2LINE_NAMES "addr2line")
list(APPEND _CMAKE_TOOL_VARS AR RANLIB STRIP LINKER NM OBJDUMP OBJCOPY READELF DLLTOOL ADDR2LINE)
endif()
find_program(CMAKE_AR NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ar${_CMAKE_TOOLCHAIN_SUFFIX} ${_CMAKE_ADDITIONAL_AR_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
foreach(TOOL IN LISTS _CMAKE_TOOL_VARS)
foreach(NAME IN LISTS _CMAKE_${TOOL}_NAMES)
if(NOT _CMAKE_TOOLCHAIN_PREFIX STREQUAL "")
if(NOT _CMAKE_TOOLCHAIN_SUFFIX STREQUAL "")
list(PREPEND _CMAKE_${TOOL}_NAMES ${NAME}${_CMAKE_TOOLCHAIN_SUFFIX})
endif()
list(PREPEND _CMAKE_${TOOL}_NAMES ${_CMAKE_TOOLCHAIN_PREFIX}${NAME})
endif()
if(NOT _CMAKE_TOOLCHAIN_SUFFIX STREQUAL "")
list(PREPEND _CMAKE_${TOOL}_NAMES ${_CMAKE_TOOLCHAIN_PREFIX}${NAME}${_CMAKE_TOOLCHAIN_SUFFIX})
endif()
endforeach()
find_program(CMAKE_${TOOL} NAMES ${_CMAKE_${TOOL}_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
endforeach()
find_program(CMAKE_RANLIB NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ranlib ${_CMAKE_ADDITIONAL_RANLIB_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
if(NOT CMAKE_RANLIB)
if(NOT CMAKE_RANLIB)
set(CMAKE_RANLIB : CACHE INTERNAL "noop for ranlib")
endif()
find_program(CMAKE_STRIP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}strip${_CMAKE_TOOLCHAIN_SUFFIX} ${_CMAKE_ADDITIONAL_STRIP_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
find_program(CMAKE_LINKER NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ld ${_CMAKE_ADDITIONAL_LINKER_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
find_program(CMAKE_NM NAMES ${_CMAKE_TOOLCHAIN_PREFIX}nm ${_CMAKE_ADDITIONAL_NM_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
find_program(CMAKE_OBJDUMP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objdump ${_CMAKE_ADDITIONAL_OBJDUMP_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
find_program(CMAKE_OBJCOPY NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objcopy ${_CMAKE_ADDITIONAL_OBJCOPY_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
find_program(CMAKE_READELF NAMES ${_CMAKE_TOOLCHAIN_PREFIX}readelf ${_CMAKE_ADDITIONAL_READELF_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
find_program(CMAKE_DLLTOOL NAMES ${_CMAKE_TOOLCHAIN_PREFIX}dlltool ${_CMAKE_ADDITIONAL_DLLTOOL_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
find_program(CMAKE_ADDR2LINE NAMES ${_CMAKE_TOOLCHAIN_PREFIX}addr2line ${_CMAKE_ADDITIONAL_ADDR2LINE_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
list(APPEND _CMAKE_TOOL_VARS AR RANLIB STRIP LINKER NM OBJDUMP OBJCOPY READELF DLLTOOL ADDR2LINE)
endif()
if(CMAKE_PLATFORM_HAS_INSTALLNAME)
find_program(CMAKE_INSTALL_NAME_TOOL NAMES ${_CMAKE_TOOLCHAIN_PREFIX}install_name_tool HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
......@@ -157,7 +157,7 @@ foreach(var IN LISTS _CMAKE_TOOL_VARS)
if(_CMAKE_TOOL_CACHED)
mark_as_advanced(CMAKE_${var})
endif()
unset(_CMAKE_ADDITIONAL_${var}_NAMES)
unset(_CMAKE_${var}_NAMES)
endforeach()
unset(_CMAKE_TOOL_VARS)
unset(_CMAKE_TOOL_CACHED)
......@@ -2,6 +2,12 @@ if(NOT DEFINED _CMAKE_PROCESSING_LANGUAGE OR _CMAKE_PROCESSING_LANGUAGE STREQUAL
message(FATAL_ERROR "Internal error: _CMAKE_PROCESSING_LANGUAGE is not set")
endif()
# Ubuntu:
# * /usr/bin/llvm-ar-9
# * /usr/bin/llvm-ranlib-9
string(REGEX MATCH "^([0-9]+)" __version_x
"${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_VERSION}")
# Debian:
# * /usr/bin/llvm-ar-4.0
# * /usr/bin/llvm-ranlib-4.0
......@@ -19,6 +25,7 @@ set(__clang_hints ${__clang_hint_1} ${__clang_hint_2})
# http://manpages.ubuntu.com/manpages/precise/en/man1/llvm-ar.1.html
find_program(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_AR NAMES
"${_CMAKE_TOOLCHAIN_PREFIX}llvm-ar-${__version_x_y}"
"${_CMAKE_TOOLCHAIN_PREFIX}llvm-ar-${__version_x}"
"${_CMAKE_TOOLCHAIN_PREFIX}llvm-ar"
HINTS ${__clang_hints}
DOC "LLVM archiver"
......@@ -28,6 +35,7 @@ mark_as_advanced(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_AR)
# http://manpages.ubuntu.com/manpages/precise/en/man1/llvm-ranlib.1.html
find_program(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_RANLIB NAMES
"${_CMAKE_TOOLCHAIN_PREFIX}llvm-ranlib-${__version_x_y}"
"${_CMAKE_TOOLCHAIN_PREFIX}llvm-ranlib-${__version_x}"
"${_CMAKE_TOOLCHAIN_PREFIX}llvm-ranlib"
HINTS ${__clang_hints}
DOC "Generate index for LLVM archive"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment