Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 1 | # |
Jonny Svärd | 54add98 | 2024-04-19 15:22:22 +0200 | [diff] [blame^] | 2 | # SPDX-FileCopyrightText: Copyright 2020-2022, 2024 Arm Limited and/or its affiliates <open-source-office@arm.com> |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 3 | # SPDX-License-Identifier: Apache-2.0 |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the License); you may |
| 6 | # not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | |
Kristofer Jonsson | ec45155 | 2021-06-04 18:02:59 +0200 | [diff] [blame] | 18 | set(TARGET_CPU "cortex-m4" CACHE STRING "Target CPU") |
Ledion Daja | ba6210b | 2022-06-21 12:06:59 +0200 | [diff] [blame] | 19 | string(TOLOWER ${TARGET_CPU} CMAKE_SYSTEM_PROCESSOR) |
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 | |
Ledion Daja | ba6210b | 2022-06-21 12:06:59 +0200 | [diff] [blame] | 27 | set(CMAKE_EXECUTABLE_SUFFIX ".elf") |
| 28 | set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) |
| 29 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) |
| 30 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) |
| 31 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 32 | |
Ledion Daja | ba6210b | 2022-06-21 12:06:59 +0200 | [diff] [blame] | 33 | # Select C/C++ version |
Kristofer Jonsson | e277674 | 2021-11-18 16:12:46 +0100 | [diff] [blame] | 34 | set(CMAKE_C_STANDARD 11) |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 35 | set(CMAKE_CXX_STANDARD 14) |
| 36 | |
Ledion Daja | ba6210b | 2022-06-21 12:06:59 +0200 | [diff] [blame] | 37 | # Link target |
| 38 | string(REGEX MATCH "^cortex-m([0-9]+)([a-z]*)" __LINK_TARGET ${CMAKE_SYSTEM_PROCESSOR}) |
| 39 | if (CMAKE_SYSTEM_PROCESSOR MATCHES "nodsp") |
| 40 | string(APPEND __LINK_TARGET ".no_dsp") |
| 41 | endif() |
| 42 | if (CMAKE_SYSTEM_PROCESSOR MATCHES "nofp") |
| 43 | string(APPEND __LINK_TARGET ".no_fp") |
| 44 | endif() |
| 45 | |
| 46 | if (CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m55") |
| 47 | set(__LINK_TARGET 8.1-M.Main.dsp) |
| 48 | endif() |
| 49 | |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 50 | # Compile options |
| 51 | add_compile_options( |
Ledion Daja | ba6210b | 2022-06-21 12:06:59 +0200 | [diff] [blame] | 52 | -mcpu=${CMAKE_SYSTEM_PROCESSOR} |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 53 | -mthumb |
| 54 | "$<$<CONFIG:DEBUG>:-gdwarf-3>" |
| 55 | "$<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables;-fno-rtti;-fno-exceptions>") |
| 56 | |
Kristofer Jonsson | 1c62899 | 2021-05-26 12:02:30 +0200 | [diff] [blame] | 57 | # Compile defines |
| 58 | add_compile_definitions( |
| 59 | "$<$<NOT:$<CONFIG:DEBUG>>:NDEBUG>") |
| 60 | |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 61 | # Link options |
| 62 | add_link_options( |
| 63 | --cpu=${__LINK_TARGET} |
| 64 | --lto |
| 65 | --info common,debug,sizes,totals,veneers,unused |
| 66 | --symbols |
Jonny Svärd | 54add98 | 2024-04-19 15:22:22 +0200 | [diff] [blame^] | 67 | --diag_suppress=L6439W,L6314W) |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 68 | |
| 69 | # Compilation warnings |
| 70 | add_compile_options( |
| 71 | -Wall |
| 72 | -Wextra |
Kristofer Jonsson | 29467e0 | 2021-11-26 16:10:43 +0100 | [diff] [blame] | 73 | |
| 74 | -Wcast-align |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 75 | -Wdouble-promotion |
Kristofer Jonsson | 29467e0 | 2021-11-26 16:10:43 +0100 | [diff] [blame] | 76 | -Wformat |
| 77 | -Wmissing-field-initializers |
| 78 | -Wnull-dereference |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 79 | -Wredundant-decls |
| 80 | -Wshadow |
Kristofer Jonsson | 29467e0 | 2021-11-26 16:10:43 +0100 | [diff] [blame] | 81 | -Wswitch-default |
| 82 | -Wunused |
| 83 | ) |