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 # Load toolchain file
if(NOT CMAKE_TOOLCHAIN_FILE OR MBED_TOOLCHAIN_FILE_USED) if(NOT CMAKE_TOOLCHAIN_FILE OR MBED_TOOLCHAIN_FILE_USED)
set(MBED_TOOLCHAIN_FILE_USED TRUE CACHE INTERNAL "") 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() endif()
# Specify available build profiles and add options for the selected build profile # 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" "-mfpu=vfpv3"
"-mfloat-abi=softfp" "-mfloat-abi=softfp"
"-mno-unaligned-access" "-mno-unaligned-access"
"-mcpu=${CMAKE_SYSTEM_PROCESSOR}" "-mcpu=${MBED_CPU_CORE}"
) )
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM") elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
list(APPEND common_options list(APPEND common_options
"-mfpu=vfpv3" "-mfpu=vfpv3"
"-mfloat-abi=hard" "-mfloat-abi=hard"
"-mcpu=${CMAKE_SYSTEM_PROCESSOR}" "-mcpu=${MBED_CPU_CORE}"
) )
endif() endif()

View File

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

View File

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

View File

@ -12,11 +12,15 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
"-mcpu=cortex-m4" "-mcpu=cortex-m4"
"-mfpu=none" "-mfpu=none"
) )
#Necessary as the linker does not always detect if(deprecated_system_processor)
#the architecture from the objectfiles correctly. # Normally `--cpu` is not needed, because `armlink` can infer
list(APPEND link_options # features from object files. But CMake versions below 3.21
"--cpu=Cortex-M4.no_fp" # 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() endif()
function(mbed_set_cpu_core_definitions target) 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") 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) set(${output_response_file_path} @${CMAKE_CURRENT_BINARY_DIR}/compile_time_defs.txt PARENT_SCOPE)
endfunction() 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
set(CMAKE_SYSTEM_PROCESSOR cortex-a9) # automatically add compile and link options for the Arm Compiler.
elseif (MBED_CPU_CORE STREQUAL Cortex-A5) # Note: From version 3.21, CMake by default (policy CMP0123 set to NEW) does not
set(CMAKE_SYSTEM_PROCESSOR cortex-a5) # use this macro anymore, and projects have full control over compile and link
elseif (MBED_CPU_CORE STREQUAL Cortex-M0+) # options. This is because the old algorithm based on CMAKE_SYSTEM_PROCESSOR
set(CMAKE_SYSTEM_PROCESSOR cortex-m0plus) # is too restrictive and does not support things like Cortex-M33.no_dsp.no_fp.
elseif (MBED_CPU_CORE STREQUAL Cortex-M0) if(MBED_TOOLCHAIN STREQUAL "ARM")
set(CMAKE_SYSTEM_PROCESSOR cortex-m0) if(NOT POLICY CMP0123)
elseif (MBED_CPU_CORE STREQUAL Cortex-M1) # Old versions of CMake do not have CMP0123.
set(CMAKE_SYSTEM_PROCESSOR cortex-m1) # In the future, support for old versions of CMake will be
elseif (MBED_CPU_CORE STREQUAL Cortex-M23-NS) # dropped from Mbed OS.
set(CMAKE_SYSTEM_PROCESSOR cortex-m23) set(deprecated_system_processor ON)
elseif (MBED_CPU_CORE STREQUAL Cortex-M23) else()
set(CMAKE_SYSTEM_PROCESSOR cortex-m23) cmake_policy(GET CMP0123 policy_CMP0123)
elseif (MBED_CPU_CORE STREQUAL Cortex-M3) if("${policy_CMP0123}" STREQUAL "")
set(CMAKE_SYSTEM_PROCESSOR cortex-m3) # CMP0123 is unset if an old `cmake_minimum_required()` is used with a
elseif (MBED_CPU_CORE STREQUAL Cortex-M33-NS) # new CMake. Enable new CMP0123 to take advantage of the improvement
set(CMAKE_SYSTEM_PROCESSOR cortex-m33) # and dismiss deprecation warnings from CMake.
elseif (MBED_CPU_CORE STREQUAL Cortex-M33) cmake_policy(SET CMP0123 NEW)
set(CMAKE_SYSTEM_PROCESSOR cortex-m33) elseif("${policy_CMP0123}" STREQUAL "OLD")
elseif (MBED_CPU_CORE STREQUAL Cortex-M33F-NS) # Respect old CMP0123 forced by user application
set(CMAKE_SYSTEM_PROCESSOR cortex-m33) set(deprecated_system_processor ON)
elseif (MBED_CPU_CORE STREQUAL Cortex-M33F) endif()
set(CMAKE_SYSTEM_PROCESSOR cortex-m33) endif()
elseif (MBED_CPU_CORE STREQUAL Cortex-M33FE-NS) endif()
set(CMAKE_SYSTEM_PROCESSOR cortex-m33)
elseif (MBED_CPU_CORE STREQUAL Cortex-M33FE) if(deprecated_system_processor)
set(CMAKE_SYSTEM_PROCESSOR cortex-m33) if (MBED_CPU_CORE STREQUAL Cortex-A9)
elseif (MBED_CPU_CORE STREQUAL Cortex-M4) set(CMAKE_SYSTEM_PROCESSOR cortex-a9)
set(CMAKE_SYSTEM_PROCESSOR cortex-m4) elseif (MBED_CPU_CORE STREQUAL Cortex-A5)
elseif (MBED_CPU_CORE STREQUAL Cortex-M4F) set(CMAKE_SYSTEM_PROCESSOR cortex-a5)
set(CMAKE_SYSTEM_PROCESSOR cortex-m4) elseif (MBED_CPU_CORE STREQUAL Cortex-M0+)
elseif (MBED_CPU_CORE STREQUAL Cortex-M55) set(CMAKE_SYSTEM_PROCESSOR cortex-m0plus)
set(CMAKE_SYSTEM_PROCESSOR cortex-m55) elseif (MBED_CPU_CORE STREQUAL Cortex-M0)
elseif (MBED_CPU_CORE STREQUAL Cortex-M7) set(CMAKE_SYSTEM_PROCESSOR cortex-m0)
set(CMAKE_SYSTEM_PROCESSOR cortex-m7) elseif (MBED_CPU_CORE STREQUAL Cortex-M1)
elseif (MBED_CPU_CORE STREQUAL Cortex-M7F) set(CMAKE_SYSTEM_PROCESSOR cortex-m1)
set(CMAKE_SYSTEM_PROCESSOR cortex-m7) elseif (MBED_CPU_CORE STREQUAL Cortex-M23-NS)
elseif (MBED_CPU_CORE STREQUAL Cortex-M7FD) set(CMAKE_SYSTEM_PROCESSOR cortex-m23)
set(CMAKE_SYSTEM_PROCESSOR cortex-m7) elseif (MBED_CPU_CORE STREQUAL Cortex-M23)
set(CMAKE_SYSTEM_PROCESSOR cortex-m23)
elseif (MBED_CPU_CORE STREQUAL Cortex-M3)
set(CMAKE_SYSTEM_PROCESSOR cortex-m3)
elseif (MBED_CPU_CORE STREQUAL Cortex-M33-NS)
set(CMAKE_SYSTEM_PROCESSOR cortex-m33)
elseif (MBED_CPU_CORE STREQUAL Cortex-M33)
set(CMAKE_SYSTEM_PROCESSOR cortex-m33)
elseif (MBED_CPU_CORE STREQUAL Cortex-M33F-NS)
set(CMAKE_SYSTEM_PROCESSOR cortex-m33)
elseif (MBED_CPU_CORE STREQUAL Cortex-M33F)
set(CMAKE_SYSTEM_PROCESSOR cortex-m33)
elseif (MBED_CPU_CORE STREQUAL Cortex-M33FE-NS)
set(CMAKE_SYSTEM_PROCESSOR cortex-m33)
elseif (MBED_CPU_CORE STREQUAL Cortex-M33FE)
set(CMAKE_SYSTEM_PROCESSOR cortex-m33)
elseif (MBED_CPU_CORE STREQUAL Cortex-M4)
set(CMAKE_SYSTEM_PROCESSOR cortex-m4)
elseif (MBED_CPU_CORE STREQUAL Cortex-M4F)
set(CMAKE_SYSTEM_PROCESSOR cortex-m4)
elseif (MBED_CPU_CORE STREQUAL Cortex-M55)
set(CMAKE_SYSTEM_PROCESSOR cortex-m55)
elseif (MBED_CPU_CORE STREQUAL Cortex-M7)
set(CMAKE_SYSTEM_PROCESSOR cortex-m7)
elseif (MBED_CPU_CORE STREQUAL Cortex-M7F)
set(CMAKE_SYSTEM_PROCESSOR cortex-m7)
elseif (MBED_CPU_CORE STREQUAL Cortex-M7FD)
set(CMAKE_SYSTEM_PROCESSOR cortex-m7)
endif()
endif() endif()
# Compiler setup # Compiler setup

View File

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