ARMClang: Fix regression in check for working compiler

Given the compiler to use, `CMakeFindBinUtils.cmake` automatically
determines a number of tools including linker (CMAKE_LINKER) and archiver
(CMAKE_AR) and stores them in a generated file `CMakeCCompiler.cmake` as
non-CACHE entries. The compiler-specific ARMClang.cmake then tries to
override CMAKE_LINKER and CMAKE_AR as CACHE entries.

Following the introduction of CMP0126, which is set to NEW in the test
for a working compiler, setting a CACHE entry does not replace a normal
entry of the same name anymore, resulting in a failed test due to wrong
linker and archiver.

To fix this, set CMAKE_LINKER and CMAKE_AR for ARMClang directly in
`CMakeFindBinUtils.cmake` as is done for other compilers.  Check
for them in `ARMClang.cmake` to safeguard cases when a project explicitly
includes `ARMClang.cmake` prior to compiler determination (which some
projects do to work around other problems in older CMake versions).
This commit is contained in:
Lingkai Dong
2021-07-13 15:32:04 +01:00
committed by Brad King
parent 00e8292434
commit 509ef50a06
2 changed files with 9 additions and 11 deletions

View File

@@ -134,6 +134,9 @@ else()
list(PREPEND _CMAKE_READELF_NAMES "llvm-readelf")
list(PREPEND _CMAKE_DLLTOOL_NAMES "llvm-dlltool")
list(PREPEND _CMAKE_ADDR2LINE_NAMES "llvm-addr2line")
elseif("${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL ARMClang)
list(PREPEND _CMAKE_AR_NAMES "armar")
list(PREPEND _CMAKE_LINKER_NAMES "armlink")
endif()
list(APPEND _CMAKE_TOOL_VARS AR RANLIB STRIP LINKER NM OBJDUMP OBJCOPY READELF DLLTOOL ADDR2LINE)

View File

@@ -1,6 +1,12 @@
if(_ARMClang_CMAKE_LOADED)
return()
endif()
# This file requires CMAKE_LINKER and CMAKE_AR set by CMakeFindBinUtils.cmake.
if(NOT (DEFINED CMAKE_LINKER AND DEFINED CMAKE_AR))
return()
endif()
set(_ARMClang_CMAKE_LOADED TRUE)
# Save the CMP0123 setting in a variable used both below and by try_compile.
@@ -9,19 +15,8 @@ cmake_policy(GET CMP0123 CMAKE_ARMClang_CMP0123)
cmake_policy(PUSH)
cmake_policy(SET CMP0057 NEW) # if IN_LIST
get_filename_component(_CMAKE_C_TOOLCHAIN_LOCATION "${CMAKE_C_COMPILER}" PATH)
get_filename_component(_CMAKE_CXX_TOOLCHAIN_LOCATION "${CMAKE_CXX_COMPILER}" PATH)
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
find_program(CMAKE_ARMClang_LINKER armlink HINTS "${_CMAKE_C_TOOLCHAIN_LOCATION}" "${_CMAKE_CXX_TOOLCHAIN_LOCATION}" )
find_program(CMAKE_ARMClang_AR armar HINTS "${_CMAKE_C_TOOLCHAIN_LOCATION}" "${_CMAKE_CXX_TOOLCHAIN_LOCATION}" )
set(CMAKE_LINKER "${CMAKE_ARMClang_LINKER}" CACHE FILEPATH "The ARMClang linker" FORCE)
mark_as_advanced(CMAKE_ARMClang_LINKER)
set(CMAKE_AR "${CMAKE_ARMClang_AR}" CACHE FILEPATH "The ARMClang archiver" FORCE)
mark_as_advanced(CMAKE_ARMClang_AR)
if (CMAKE_LINKER MATCHES "armlink")
set(__CMAKE_ARMClang_USING_armlink TRUE)
set(CMAKE_LIBRARY_PATH_FLAG "--userlibpath=")