Merge pull request #14575 from LDong-Arm/cmake_armclang_fix

CMake: Enable improved armclang support in CMake 3.21
pull/14978/head
Martin Kojtal 2021-07-29 10:32:27 +01:00 committed by GitHub
commit bad4aa61ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 101 additions and 64 deletions

View File

@ -16,7 +16,9 @@ include(mbed_set_post_build)
# Load toolchain file
if(NOT CMAKE_TOOLCHAIN_FILE OR MBED_TOOLCHAIN_FILE_USED)
set(MBED_TOOLCHAIN_FILE_USED TRUE CACHE INTERNAL "")
include(mbed_toolchain)
# We want to bring CMP0123 we set in mbed_toolchain.cmake
# to the whole Mbed OS.
include(mbed_toolchain NO_POLICY_SCOPE)
endif()
# Specify available build profiles and add options for the selected build profile

View File

@ -8,13 +8,13 @@ if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
"-mfpu=vfpv3"
"-mfloat-abi=softfp"
"-mno-unaligned-access"
"-mcpu=${CMAKE_SYSTEM_PROCESSOR}"
"-mcpu=${MBED_CPU_CORE}"
)
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
list(APPEND common_options
"-mfpu=vfpv3"
"-mfloat-abi=hard"
"-mcpu=${CMAKE_SYSTEM_PROCESSOR}"
"-mcpu=${MBED_CPU_CORE}"
)
endif()

View File

@ -12,13 +12,15 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
"-mcpu=cortex-m33+nodsp"
"-mfpu=none"
)
if(deprecated_system_processor)
# Normally `--cpu` is not needed, because `armlink` can infer
# features from object files. But CMake versions below 3.21
# automatically add `--cpu=${CMAKE_SYSTEM_PROCESSOR}` which is
# incorrect, so as a workaround we need to add `no_fp`.
list(APPEND link_options
# Necessary as the linker does not always detect
# the architecture from the objectfiles correctly.
# Also, the complete flag should be "--cpu=Cortex-M33.no_dsp.no_fp"
# but this currently conflicts with CMake's compiler test until fixed
"--cpu=Cortex-M33.no_fp"
)
endif()
endif()
function(mbed_set_cpu_core_definitions target)

View File

@ -12,13 +12,15 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
"-mcpu=cortex-m33+nodsp"
"-mfpu=none"
)
if(deprecated_system_processor)
# Normally `--cpu` is not needed, because `armlink` can infer
# features from object files. But CMake versions below 3.21
# automatically add `--cpu=${CMAKE_SYSTEM_PROCESSOR}` which is
# incorrect, so as a workaround we need to add `no_fp`.
list(APPEND link_options
# Necessary as the linker does not always detect
# the architecture from the objectfiles correctly.
# Also, the complete flag should be "--cpu=Cortex-M33.no_dsp.no_fp"
# but this currently conflicts with CMake's compiler test until fixed
"--cpu=Cortex-M33.no_fp"
)
endif()
endif()
function(mbed_set_cpu_core_definitions target)

View File

@ -12,11 +12,15 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
"-mcpu=cortex-m4"
"-mfpu=none"
)
#Necessary as the linker does not always detect
#the architecture from the objectfiles correctly.
if(deprecated_system_processor)
# Normally `--cpu` is not needed, because `armlink` can infer
# features from object files. But CMake versions below 3.21
# automatically add `--cpu=${CMAKE_SYSTEM_PROCESSOR}` which is
# incorrect, so as a workaround we need to add `no_fp`.
list(APPEND link_options
"--cpu=Cortex-M4.no_fp"
)
endif()
endif()
function(mbed_set_cpu_core_definitions target)

View File

@ -22,47 +22,75 @@ function(mbed_generate_options_for_linker target output_response_file_path)
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/compile_time_defs.txt" CONTENT "${_compile_definitions}\n")
set(${output_response_file_path} @${CMAKE_CURRENT_BINARY_DIR}/compile_time_defs.txt PARENT_SCOPE)
endfunction()
# Set the system processor depending on the CPU core type
if (MBED_CPU_CORE STREQUAL Cortex-A9)
# Backward compatibility with older CMake which uses CMAKE_SYSTEM_PROCESSOR to
# automatically add compile and link options for the Arm Compiler.
# Note: From version 3.21, CMake by default (policy CMP0123 set to NEW) does not
# use this macro anymore, and projects have full control over compile and link
# options. This is because the old algorithm based on CMAKE_SYSTEM_PROCESSOR
# is too restrictive and does not support things like Cortex-M33.no_dsp.no_fp.
if(MBED_TOOLCHAIN STREQUAL "ARM")
if(NOT POLICY CMP0123)
# Old versions of CMake do not have CMP0123.
# In the future, support for old versions of CMake will be
# dropped from Mbed OS.
set(deprecated_system_processor ON)
else()
cmake_policy(GET CMP0123 policy_CMP0123)
if("${policy_CMP0123}" STREQUAL "")
# CMP0123 is unset if an old `cmake_minimum_required()` is used with a
# new CMake. Enable new CMP0123 to take advantage of the improvement
# and dismiss deprecation warnings from CMake.
cmake_policy(SET CMP0123 NEW)
elseif("${policy_CMP0123}" STREQUAL "OLD")
# Respect old CMP0123 forced by user application
set(deprecated_system_processor ON)
endif()
endif()
endif()
if(deprecated_system_processor)
if (MBED_CPU_CORE STREQUAL Cortex-A9)
set(CMAKE_SYSTEM_PROCESSOR cortex-a9)
elseif (MBED_CPU_CORE STREQUAL Cortex-A5)
elseif (MBED_CPU_CORE STREQUAL Cortex-A5)
set(CMAKE_SYSTEM_PROCESSOR cortex-a5)
elseif (MBED_CPU_CORE STREQUAL Cortex-M0+)
elseif (MBED_CPU_CORE STREQUAL Cortex-M0+)
set(CMAKE_SYSTEM_PROCESSOR cortex-m0plus)
elseif (MBED_CPU_CORE STREQUAL Cortex-M0)
elseif (MBED_CPU_CORE STREQUAL Cortex-M0)
set(CMAKE_SYSTEM_PROCESSOR cortex-m0)
elseif (MBED_CPU_CORE STREQUAL Cortex-M1)
elseif (MBED_CPU_CORE STREQUAL Cortex-M1)
set(CMAKE_SYSTEM_PROCESSOR cortex-m1)
elseif (MBED_CPU_CORE STREQUAL Cortex-M23-NS)
elseif (MBED_CPU_CORE STREQUAL Cortex-M23-NS)
set(CMAKE_SYSTEM_PROCESSOR cortex-m23)
elseif (MBED_CPU_CORE STREQUAL Cortex-M23)
elseif (MBED_CPU_CORE STREQUAL Cortex-M23)
set(CMAKE_SYSTEM_PROCESSOR cortex-m23)
elseif (MBED_CPU_CORE STREQUAL Cortex-M3)
elseif (MBED_CPU_CORE STREQUAL Cortex-M3)
set(CMAKE_SYSTEM_PROCESSOR cortex-m3)
elseif (MBED_CPU_CORE STREQUAL Cortex-M33-NS)
elseif (MBED_CPU_CORE STREQUAL Cortex-M33-NS)
set(CMAKE_SYSTEM_PROCESSOR cortex-m33)
elseif (MBED_CPU_CORE STREQUAL Cortex-M33)
elseif (MBED_CPU_CORE STREQUAL Cortex-M33)
set(CMAKE_SYSTEM_PROCESSOR cortex-m33)
elseif (MBED_CPU_CORE STREQUAL Cortex-M33F-NS)
elseif (MBED_CPU_CORE STREQUAL Cortex-M33F-NS)
set(CMAKE_SYSTEM_PROCESSOR cortex-m33)
elseif (MBED_CPU_CORE STREQUAL Cortex-M33F)
elseif (MBED_CPU_CORE STREQUAL Cortex-M33F)
set(CMAKE_SYSTEM_PROCESSOR cortex-m33)
elseif (MBED_CPU_CORE STREQUAL Cortex-M33FE-NS)
elseif (MBED_CPU_CORE STREQUAL Cortex-M33FE-NS)
set(CMAKE_SYSTEM_PROCESSOR cortex-m33)
elseif (MBED_CPU_CORE STREQUAL Cortex-M33FE)
elseif (MBED_CPU_CORE STREQUAL Cortex-M33FE)
set(CMAKE_SYSTEM_PROCESSOR cortex-m33)
elseif (MBED_CPU_CORE STREQUAL Cortex-M4)
elseif (MBED_CPU_CORE STREQUAL Cortex-M4)
set(CMAKE_SYSTEM_PROCESSOR cortex-m4)
elseif (MBED_CPU_CORE STREQUAL Cortex-M4F)
elseif (MBED_CPU_CORE STREQUAL Cortex-M4F)
set(CMAKE_SYSTEM_PROCESSOR cortex-m4)
elseif (MBED_CPU_CORE STREQUAL Cortex-M55)
elseif (MBED_CPU_CORE STREQUAL Cortex-M55)
set(CMAKE_SYSTEM_PROCESSOR cortex-m55)
elseif (MBED_CPU_CORE STREQUAL Cortex-M7)
elseif (MBED_CPU_CORE STREQUAL Cortex-M7)
set(CMAKE_SYSTEM_PROCESSOR cortex-m7)
elseif (MBED_CPU_CORE STREQUAL Cortex-M7F)
elseif (MBED_CPU_CORE STREQUAL Cortex-M7F)
set(CMAKE_SYSTEM_PROCESSOR cortex-m7)
elseif (MBED_CPU_CORE STREQUAL Cortex-M7FD)
elseif (MBED_CPU_CORE STREQUAL Cortex-M7FD)
set(CMAKE_SYSTEM_PROCESSOR cortex-m7)
endif()
endif()
# Compiler setup

View File

@ -4,7 +4,6 @@
set(CMAKE_ASM_COMPILER "armclang")
set(CMAKE_C_COMPILER "armclang")
set(CMAKE_CXX_COMPILER "armclang")
set(CMAKE_AR "armar")
set(ARM_ELF2BIN "fromelf")
set_property(GLOBAL PROPERTY ELF2BIN ${ARM_ELF2BIN})