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