Kristofer Jonsson | 6f4cb2a | 2020-08-17 16:57:43 +0200 | [diff] [blame] | 1 | # |
Kristofer Jonsson | 1efcc3f | 2021-02-16 17:40:25 +0100 | [diff] [blame] | 2 | # Copyright (c) 2019-2021 Arm Limited. All rights reserved. |
Kristofer Jonsson | 6f4cb2a | 2020-08-17 16:57:43 +0200 | [diff] [blame] | 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") |
Kristofer Jonsson | 1efcc3f | 2021-02-16 17:40:25 +0100 | [diff] [blame] | 27 | set(CMAKE_ASM_COMPILER "armclang") |
Kristofer Jonsson | 6f4cb2a | 2020-08-17 16:57:43 +0200 | [diff] [blame] | 28 | 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)") |
| 29 | |
| 30 | set(CMAKE_C_STANDARD 99) |
| 31 | set(CMAKE_CXX_STANDARD 11) |
| 32 | |
| 33 | # The system processor could for example be set to cortex-m33+nodsp+nofp. |
| 34 | set(__CPU_COMPILE_TARGET ${CMAKE_SYSTEM_PROCESSOR}) |
| 35 | string(REPLACE "+" ";" __CPU_FEATURES ${__CPU_COMPILE_TARGET}) |
| 36 | list(POP_FRONT __CPU_FEATURES CMAKE_SYSTEM_PROCESSOR) |
| 37 | |
| 38 | string(FIND ${__CPU_COMPILE_TARGET} "+" __OFFSET) |
| 39 | if(__OFFSET GREATER_EQUAL 0) |
| 40 | string(SUBSTRING ${__CPU_COMPILE_TARGET} ${__OFFSET} -1 CPU_FEATURES) |
| 41 | endif() |
| 42 | |
| 43 | # Add -mcpu to the compile options to override the -mcpu the CMake toolchain adds |
Kristofer Jonsson | 1efcc3f | 2021-02-16 17:40:25 +0100 | [diff] [blame] | 44 | add_compile_options( |
| 45 | -mcpu=${__CPU_COMPILE_TARGET} |
| 46 | "$<$<COMPILE_LANGUAGE:ASM>:-masm=auto;--target=arm-arm-none-eabi>") |
Kristofer Jonsson | 6f4cb2a | 2020-08-17 16:57:43 +0200 | [diff] [blame] | 47 | |
Kristofer Jonsson | d273d8e | 2020-10-13 09:35:55 +0200 | [diff] [blame] | 48 | # Set floating point unit |
| 49 | if("${__CPU_COMPILE_TARGET}" MATCHES "\\+fp") |
| 50 | set(FLOAT hard) |
| 51 | elseif("${__CPU_COMPILE_TARGET}" MATCHES "\\+nofp") |
| 52 | set(FLOAT soft) |
| 53 | elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m33" OR |
Kristofer Jonsson | 1efcc3f | 2021-02-16 17:40:25 +0100 | [diff] [blame] | 54 | "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m4" OR |
| 55 | "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m55" OR |
| 56 | "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m7") |
Kristofer Jonsson | d273d8e | 2020-10-13 09:35:55 +0200 | [diff] [blame] | 57 | set(FLOAT hard) |
| 58 | else() |
| 59 | set(FLOAT soft) |
| 60 | endif() |
| 61 | |
| 62 | add_compile_options(-mfloat-abi=${FLOAT}) |
| 63 | #add_link_options(-mfloat-abi=${FLOAT}) |
| 64 | |
Kristofer Jonsson | 6f4cb2a | 2020-08-17 16:57:43 +0200 | [diff] [blame] | 65 | # Link target |
| 66 | set(__CPU_LINK_TARGET ${CMAKE_SYSTEM_PROCESSOR}) |
| 67 | if("nodsp" IN_LIST __CPU_FEATURES) |
| 68 | string(APPEND __CPU_LINK_TARGET ".no_dsp") |
| 69 | endif() |
| 70 | if("nofp" IN_LIST __CPU_FEATURES) |
| 71 | string(APPEND __CPU_LINK_TARGET ".no_fp") |
| 72 | endif() |
| 73 | |
| 74 | if(CMAKE_SYSTEM_PROCESSOR STREQUAL "cortex-m55") |
| 75 | set(__CPU_LINK_TARGET 8.1-M.Main.dsp) |
| 76 | endif() |
| 77 | |
| 78 | add_link_options(--cpu=${__CPU_LINK_TARGET}) |
| 79 | add_link_options(--lto --info common,debug,sizes,totals,veneers,unused --symbols --diag_suppress=L6439W) |
| 80 | |
| 81 | # |
| 82 | # Compile options |
| 83 | # |
| 84 | |
| 85 | add_compile_options(-Wall -Wextra |
Kristofer Jonsson | 1efcc3f | 2021-02-16 17:40:25 +0100 | [diff] [blame] | 86 | -Wsign-compare |
| 87 | -Wunused |
| 88 | -Wswitch-default |
| 89 | -Wformat |
| 90 | -Wdouble-promotion |
| 91 | -Wredundant-decls |
| 92 | -Wshadow |
| 93 | -Wcast-align |
| 94 | -Wnull-dereference |
| 95 | -Wno-deprecated-register |
| 96 | -Wno-format-extra-args |
| 97 | -Wno-missing-field-initializers |
| 98 | -Wno-unused-function |
| 99 | -Wno-unused-label |
| 100 | -Wno-unused-parameter |
| 101 | -Wno-return-type) |
Kristofer Jonsson | 6f4cb2a | 2020-08-17 16:57:43 +0200 | [diff] [blame] | 102 | add_compile_options(-fno-unwind-tables -fno-rtti -fno-exceptions) |
| 103 | add_compile_options(-mthumb) |
| 104 | add_compile_options("$<$<CONFIG:DEBUG>:-gdwarf-3>") |