Find appropriate binutils when cross-compiling with clang

One way to use clang as a cross-compiler is to create
a symlink named <target>-clang, which is equivalent to
running

 clang -target <target>

Extract the toolchain prefix to find the binutils executables.
This commit is contained in:
Stephen Kelly 2013-10-20 13:32:23 +02:00
parent fd818b2ff4
commit b84f5c2ef1
2 changed files with 4 additions and 4 deletions

View File

@ -154,9 +154,9 @@ endif ()
# "arm-unknown-nto-qnx6" instead of the correct "arm-unknown-nto-qnx6.3.0-" # "arm-unknown-nto-qnx6" instead of the correct "arm-unknown-nto-qnx6.3.0-"
if (CMAKE_CROSSCOMPILING AND NOT _CMAKE_TOOLCHAIN_PREFIX) if (CMAKE_CROSSCOMPILING AND NOT _CMAKE_TOOLCHAIN_PREFIX)
if("${CMAKE_C_COMPILER_ID}" MATCHES "GNU") if("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
get_filename_component(COMPILER_BASENAME "${CMAKE_C_COMPILER}" NAME) get_filename_component(COMPILER_BASENAME "${CMAKE_C_COMPILER}" NAME)
if (COMPILER_BASENAME MATCHES "^(.+-)g?cc(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$") if (COMPILER_BASENAME MATCHES "^(.+-)(clang|g?cc)(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1}) set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
endif () endif ()

View File

@ -152,9 +152,9 @@ endif ()
if (CMAKE_CROSSCOMPILING AND NOT _CMAKE_TOOLCHAIN_PREFIX) if (CMAKE_CROSSCOMPILING AND NOT _CMAKE_TOOLCHAIN_PREFIX)
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
get_filename_component(COMPILER_BASENAME "${CMAKE_CXX_COMPILER}" NAME) get_filename_component(COMPILER_BASENAME "${CMAKE_CXX_COMPILER}" NAME)
if (COMPILER_BASENAME MATCHES "^(.+-)[gc]\\+\\+(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$") if (COMPILER_BASENAME MATCHES "^(.+-)(clan)?[gc]\\+\\+(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1}) set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
endif () endif ()