diff options
author | Lingkai Dong <lingkai.dong@arm.com> | 2021-07-13 15:32:04 +0100 |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-07-14 09:45:09 -0400 |
commit | 509ef50a06fd690a85ca245a7221d001a3d6937f (patch) | |
tree | 63fe52f0d2af0459a0c56d7cd4288d28496b2258 | |
parent | 00e8292434871887f174cfc1a8b3941abefe4cb1 (diff) | |
download | cmake-509ef50a06fd690a85ca245a7221d001a3d6937f.tar.gz |
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).
-rw-r--r-- | Modules/CMakeFindBinUtils.cmake | 3 | ||||
-rw-r--r-- | Modules/Compiler/ARMClang.cmake | 17 |
2 files changed, 9 insertions, 11 deletions
diff --git a/Modules/CMakeFindBinUtils.cmake b/Modules/CMakeFindBinUtils.cmake index ec6bc8d8ce..3162ec57fa 100644 --- a/Modules/CMakeFindBinUtils.cmake +++ b/Modules/CMakeFindBinUtils.cmake @@ -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) diff --git a/Modules/Compiler/ARMClang.cmake b/Modules/Compiler/ARMClang.cmake index 354c11ddbf..c83922079a 100644 --- a/Modules/Compiler/ARMClang.cmake +++ b/Modules/Compiler/ARMClang.cmake @@ -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=") |