Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 1 | # |
Kristofer Jonsson | 1c62899 | 2021-05-26 12:02:30 +0200 | [diff] [blame] | 2 | # Copyright (c) 2020-2021 Arm Limited. All rights reserved. |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [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 | |
Kristofer Jonsson | ec45155 | 2021-06-04 18:02:59 +0200 | [diff] [blame] | 19 | set(TARGET_CPU "cortex-m4" CACHE STRING "Target CPU") |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 20 | |
| 21 | set(CMAKE_SYSTEM_NAME Generic) |
| 22 | set(CMAKE_C_COMPILER "armclang") |
| 23 | set(CMAKE_CXX_COMPILER "armclang") |
liodek01 | cbf1d6d | 2021-06-30 12:48:31 +0300 | [diff] [blame] | 24 | set(CMAKE_ASM_COMPILER "armclang") |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 25 | set(CMAKE_LINKER "armlink") |
| 26 | |
| 27 | # Convert TARGET_CPU=Cortex-M33+nofp+nodsp into |
| 28 | # - CMAKE_SYSTEM_PROCESSOR=cortex-m33 |
| 29 | # - __CPU_FEATURES=no-fp;no-dsp |
| 30 | string(REPLACE "+" ";" __CPU_FEATURES ${TARGET_CPU}) |
| 31 | list(POP_FRONT __CPU_FEATURES CMAKE_SYSTEM_PROCESSOR) |
| 32 | string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} CMAKE_SYSTEM_PROCESSOR) |
| 33 | |
| 34 | # Link target |
| 35 | set(__LINK_TARGET ${CMAKE_SYSTEM_PROCESSOR}) |
| 36 | |
| 37 | if ("nodsp" IN_LIST __CPU_FEATURES) |
| 38 | string(APPEND __LINK_TARGET ".no_dsp") |
| 39 | endif() |
| 40 | |
| 41 | if ("nofp" IN_LIST __CPU_FEATURES) |
| 42 | string(APPEND __LINK_TARGET ".no_fp") |
| 43 | endif() |
| 44 | |
| 45 | if (CMAKE_SYSTEM_PROCESSOR STREQUAL "cortex-m55") |
| 46 | set(__LINK_TARGET 8.1-M.Main.dsp) |
| 47 | endif() |
| 48 | |
| 49 | # Define C/C++ standards |
Kristofer Jonsson | e277674 | 2021-11-18 16:12:46 +0100 | [diff] [blame] | 50 | set(CMAKE_C_STANDARD 11) |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 51 | set(CMAKE_CXX_STANDARD 14) |
| 52 | |
| 53 | # Compile options |
| 54 | add_compile_options( |
| 55 | -mcpu=${TARGET_CPU} |
| 56 | -mthumb |
| 57 | "$<$<CONFIG:DEBUG>:-gdwarf-3>" |
| 58 | "$<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables;-fno-rtti;-fno-exceptions>") |
| 59 | |
Kristofer Jonsson | 1c62899 | 2021-05-26 12:02:30 +0200 | [diff] [blame] | 60 | # Compile defines |
| 61 | add_compile_definitions( |
| 62 | "$<$<NOT:$<CONFIG:DEBUG>>:NDEBUG>") |
| 63 | |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 64 | # Link options |
| 65 | add_link_options( |
| 66 | --cpu=${__LINK_TARGET} |
| 67 | --lto |
| 68 | --info common,debug,sizes,totals,veneers,unused |
| 69 | --symbols |
| 70 | --diag_suppress=L6439W) |
| 71 | |
| 72 | # Compilation warnings |
| 73 | add_compile_options( |
| 74 | -Wall |
| 75 | -Wextra |
Kristofer Jonsson | 29467e0 | 2021-11-26 16:10:43 +0100 | [diff] [blame] | 76 | |
| 77 | -Wcast-align |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 78 | -Wdouble-promotion |
Kristofer Jonsson | 29467e0 | 2021-11-26 16:10:43 +0100 | [diff] [blame] | 79 | -Wformat |
| 80 | -Wmissing-field-initializers |
| 81 | -Wnull-dereference |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 82 | -Wredundant-decls |
| 83 | -Wshadow |
Kristofer Jonsson | 29467e0 | 2021-11-26 16:10:43 +0100 | [diff] [blame] | 84 | -Wswitch-default |
| 85 | -Wunused |
| 86 | ) |