1# 2# Copyright (c) 2020-2022 Arm Limited. All rights reserved. 3# 4# SPDX-License-Identifier: Apache-2.0 5# 6# Licensed under the Apache License, Version 2.0 (the License); you may 7# not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an AS IS BASIS, WITHOUT 14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17# 18 19# Copied this file from core_platform/cmake/toolchain/arm-non-eabi-gcc.cmake And 20# modified to align better with cs300 platform 21 22set(TARGET_CPU 23 "cortex-m55" 24 CACHE STRING "Target CPU" 25) 26string(TOLOWER ${TARGET_CPU} CMAKE_SYSTEM_PROCESSOR) 27 28set(CMAKE_SYSTEM_NAME Generic) 29set(CMAKE_C_COMPILER "arm-none-eabi-gcc") 30set(CMAKE_CXX_COMPILER "arm-none-eabi-g++") 31set(CMAKE_ASM_COMPILER "arm-none-eabi-gcc") 32set(CMAKE_LINKER "arm-none-eabi-ld") 33 34set(CMAKE_EXECUTABLE_SUFFIX ".elf") 35set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) 36set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 37set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 38set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 39 40# Select C/C++ version 41set(CMAKE_C_STANDARD 11) 42set(CMAKE_CXX_STANDARD 17) 43 44set(GCC_CPU ${CMAKE_SYSTEM_PROCESSOR}) 45string(REPLACE "cortex-m85" "cortex-m55" GCC_CPU ${GCC_CPU}) 46 47# Compile options 48add_compile_options( 49 -mcpu=${GCC_CPU} -mthumb "$<$<CONFIG:DEBUG>:-gdwarf-3>" 50 "$<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables;-fno-rtti;-fno-exceptions>" 51 -fdata-sections -ffunction-sections 52) 53 54# Compile defines 55add_compile_definitions("$<$<NOT:$<CONFIG:DEBUG>>:NDEBUG>") 56 57# Link options 58add_link_options(-mcpu=${GCC_CPU} -mthumb) 59 60if(SEMIHOSTING) 61 add_link_options(--specs=rdimon.specs) 62else() 63 add_link_options(--specs=nosys.specs) 64endif() 65 66# Set floating point unit 67if(CMAKE_SYSTEM_PROCESSOR MATCHES "\\+fp") 68 set(FLOAT hard) 69elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "\\+nofp") 70 set(FLOAT soft) 71elseif( 72 CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m33(\\+|$)" 73 OR CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m55(\\+|$)" 74 OR CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m85(\\+|$)" 75) 76 set(FLOAT hard) 77elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m4(\\+|$)" 78 OR CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m7(\\+|$)" 79) 80 set(FLOAT hard) 81 set(FPU_CONFIG "fpv4-sp-d16") 82 add_compile_options(-mfpu=${FPU_CONFIG}) 83 add_link_options(-mfpu=${FPU_CONFIG}) 84else() 85 set(FLOAT soft) 86endif() 87 88if(FLOAT) 89 add_compile_options(-mfloat-abi=${FLOAT}) 90 add_link_options(-mfloat-abi=${FLOAT}) 91endif() 92 93add_link_options(LINKER:--nmagic,--gc-sections) 94 95# Compilation warnings 96add_compile_options( 97 # -Wall -Wextra -Wcast-align -Wdouble-promotion -Wformat 98 # -Wmissing-field-initializers -Wnull-dereference -Wredundant-decls -Wshadow 99 # -Wswitch -Wswitch-default -Wunused -Wno-redundant-decls 100 -Wno-psabi 101) 102