Kristofer Jonsson | 6f4cb2a | 2020-08-17 16:57:43 +0200 | [diff] [blame] | 1 | # |
| 2 | # Copyright (c) 2019-2020 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 | if (__TOOLCHAIN_LOADED) |
| 20 | return() |
| 21 | endif() |
| 22 | set(__TOOLCHAIN_LOADED TRUE) |
| 23 | |
| 24 | set(CMAKE_SYSTEM_NAME Generic) |
| 25 | set(CMAKE_C_COMPILER "armclang") |
| 26 | set(CMAKE_CXX_COMPILER "armclang") |
| 27 | set(CMAKE_SYSTEM_PROCESSOR "cortex-m33+nodsp" CACHE STRING "Select Cortex-M architure. (cortex-m0, cortex-m3, cortex-m33, cortex-m4, cortex-m55, cortex-m7, etc)") |
| 28 | |
| 29 | set(CMAKE_C_STANDARD 99) |
| 30 | set(CMAKE_CXX_STANDARD 11) |
| 31 | |
| 32 | # The system processor could for example be set to cortex-m33+nodsp+nofp. |
| 33 | set(__CPU_COMPILE_TARGET ${CMAKE_SYSTEM_PROCESSOR}) |
| 34 | string(REPLACE "+" ";" __CPU_FEATURES ${__CPU_COMPILE_TARGET}) |
| 35 | list(POP_FRONT __CPU_FEATURES CMAKE_SYSTEM_PROCESSOR) |
| 36 | |
| 37 | string(FIND ${__CPU_COMPILE_TARGET} "+" __OFFSET) |
| 38 | if(__OFFSET GREATER_EQUAL 0) |
| 39 | string(SUBSTRING ${__CPU_COMPILE_TARGET} ${__OFFSET} -1 CPU_FEATURES) |
| 40 | endif() |
| 41 | |
| 42 | # Add -mcpu to the compile options to override the -mcpu the CMake toolchain adds |
| 43 | add_compile_options(-mcpu=${__CPU_COMPILE_TARGET}) |
| 44 | |
Kristofer Jonsson | d273d8e | 2020-10-13 09:35:55 +0200 | [diff] [blame] | 45 | # Set floating point unit |
| 46 | if("${__CPU_COMPILE_TARGET}" MATCHES "\\+fp") |
| 47 | set(FLOAT hard) |
| 48 | elseif("${__CPU_COMPILE_TARGET}" MATCHES "\\+nofp") |
| 49 | set(FLOAT soft) |
| 50 | elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m33" OR |
| 51 | "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m55") |
| 52 | set(FLOAT hard) |
| 53 | else() |
| 54 | set(FLOAT soft) |
| 55 | endif() |
| 56 | |
| 57 | add_compile_options(-mfloat-abi=${FLOAT}) |
| 58 | #add_link_options(-mfloat-abi=${FLOAT}) |
| 59 | |
Kristofer Jonsson | 6f4cb2a | 2020-08-17 16:57:43 +0200 | [diff] [blame] | 60 | # Link target |
| 61 | set(__CPU_LINK_TARGET ${CMAKE_SYSTEM_PROCESSOR}) |
| 62 | if("nodsp" IN_LIST __CPU_FEATURES) |
| 63 | string(APPEND __CPU_LINK_TARGET ".no_dsp") |
| 64 | endif() |
| 65 | if("nofp" IN_LIST __CPU_FEATURES) |
| 66 | string(APPEND __CPU_LINK_TARGET ".no_fp") |
| 67 | endif() |
| 68 | |
| 69 | if(CMAKE_SYSTEM_PROCESSOR STREQUAL "cortex-m55") |
| 70 | set(__CPU_LINK_TARGET 8.1-M.Main.dsp) |
| 71 | endif() |
| 72 | |
| 73 | add_link_options(--cpu=${__CPU_LINK_TARGET}) |
| 74 | add_link_options(--lto --info common,debug,sizes,totals,veneers,unused --symbols --diag_suppress=L6439W) |
| 75 | |
| 76 | # |
| 77 | # Compile options |
| 78 | # |
| 79 | |
| 80 | add_compile_options(-Wall -Wextra |
| 81 | -Wsign-compare -Wunused -Wswitch-default -Wformat -Wdouble-promotion -Wredundant-decls -Wshadow -Wcast-align -Wnull-dereference |
| 82 | -Wno-format-extra-args -Wno-unused-function -Wno-unused-label -Wno-missing-field-initializers -Wno-return-type) |
| 83 | add_compile_options(-fno-unwind-tables -fno-rtti -fno-exceptions) |
| 84 | add_compile_options(-mthumb) |
| 85 | add_compile_options("$<$<CONFIG:DEBUG>:-gdwarf-3>") |