blob: 74ff0078c8a6ad6369d7168b118306a6bbe94219 [file] [log] [blame]
Kristofer Jonsson43ce4912020-11-20 09:42:53 +01001#
Jonny Svärd54add982024-04-19 15:22:22 +02002# SPDX-FileCopyrightText: Copyright 2020-2022, 2024 Arm Limited and/or its affiliates <open-source-office@arm.com>
Kristofer Jonsson43ce4912020-11-20 09:42:53 +01003# 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 Jonssonec451552021-06-04 18:02:59 +020018set(TARGET_CPU "cortex-m4" CACHE STRING "Target CPU")
Ledion Dajaba6210b2022-06-21 12:06:59 +020019string(TOLOWER ${TARGET_CPU} CMAKE_SYSTEM_PROCESSOR)
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010020
21set(CMAKE_SYSTEM_NAME Generic)
22set(CMAKE_C_COMPILER "armclang")
23set(CMAKE_CXX_COMPILER "armclang")
liodek01cbf1d6d2021-06-30 12:48:31 +030024set(CMAKE_ASM_COMPILER "armclang")
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010025set(CMAKE_LINKER "armlink")
26
Ledion Dajaba6210b2022-06-21 12:06:59 +020027set(CMAKE_EXECUTABLE_SUFFIX ".elf")
28set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
29set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
30set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
31set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010032
Ledion Dajaba6210b2022-06-21 12:06:59 +020033# Select C/C++ version
Kristofer Jonssone2776742021-11-18 16:12:46 +010034set(CMAKE_C_STANDARD 11)
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010035set(CMAKE_CXX_STANDARD 14)
36
Ledion Dajaba6210b2022-06-21 12:06:59 +020037# Link target
38string(REGEX MATCH "^cortex-m([0-9]+)([a-z]*)" __LINK_TARGET ${CMAKE_SYSTEM_PROCESSOR})
39if (CMAKE_SYSTEM_PROCESSOR MATCHES "nodsp")
40 string(APPEND __LINK_TARGET ".no_dsp")
41endif()
42if (CMAKE_SYSTEM_PROCESSOR MATCHES "nofp")
43 string(APPEND __LINK_TARGET ".no_fp")
44endif()
45
46if (CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m55")
47 set(__LINK_TARGET 8.1-M.Main.dsp)
48endif()
49
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010050# Compile options
51add_compile_options(
Ledion Dajaba6210b2022-06-21 12:06:59 +020052 -mcpu=${CMAKE_SYSTEM_PROCESSOR}
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010053 -mthumb
54 "$<$<CONFIG:DEBUG>:-gdwarf-3>"
55 "$<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables;-fno-rtti;-fno-exceptions>")
56
Kristofer Jonsson1c628992021-05-26 12:02:30 +020057# Compile defines
58add_compile_definitions(
59 "$<$<NOT:$<CONFIG:DEBUG>>:NDEBUG>")
60
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010061# Link options
62add_link_options(
63 --cpu=${__LINK_TARGET}
64 --lto
65 --info common,debug,sizes,totals,veneers,unused
66 --symbols
Jonny Svärd54add982024-04-19 15:22:22 +020067 --diag_suppress=L6439W,L6314W)
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010068
69# Compilation warnings
70add_compile_options(
71 -Wall
72 -Wextra
Kristofer Jonsson29467e02021-11-26 16:10:43 +010073
74 -Wcast-align
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010075 -Wdouble-promotion
Kristofer Jonsson29467e02021-11-26 16:10:43 +010076 -Wformat
77 -Wmissing-field-initializers
78 -Wnull-dereference
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010079 -Wredundant-decls
80 -Wshadow
Kristofer Jonsson29467e02021-11-26 16:10:43 +010081 -Wswitch-default
82 -Wunused
83)