blob: aa19ff40a909f2d2b402460eefe5758267d429d9 [file] [log] [blame]
Kristofer Jonsson43ce4912020-11-20 09:42:53 +01001#
Davide Grohmanna8832cc2022-05-06 16:35:16 +02002# Copyright (c) 2020-2022 Arm Limited. All rights reserved.
Kristofer Jonsson43ce4912020-11-20 09:42:53 +01003#
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 Jonssonec451552021-06-04 18:02:59 +020019set(TARGET_CPU "cortex-m4" CACHE STRING "Target CPU")
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
27# Convert TARGET_CPU=Cortex-M33+nofp+nodsp into
28# - CMAKE_SYSTEM_PROCESSOR=cortex-m33
29# - __CPU_FEATURES=no-fp;no-dsp
30string(REPLACE "+" ";" __CPU_FEATURES ${TARGET_CPU})
31list(POP_FRONT __CPU_FEATURES CMAKE_SYSTEM_PROCESSOR)
32string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} CMAKE_SYSTEM_PROCESSOR)
33
34# Link target
35set(__LINK_TARGET ${CMAKE_SYSTEM_PROCESSOR})
36
37if ("nodsp" IN_LIST __CPU_FEATURES)
38 string(APPEND __LINK_TARGET ".no_dsp")
39endif()
40
41if ("nofp" IN_LIST __CPU_FEATURES)
42 string(APPEND __LINK_TARGET ".no_fp")
43endif()
44
Davide Grohmanna8832cc2022-05-06 16:35:16 +020045if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m55")
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010046 set(__LINK_TARGET 8.1-M.Main.dsp)
47endif()
48
49# Define C/C++ standards
Kristofer Jonssone2776742021-11-18 16:12:46 +010050set(CMAKE_C_STANDARD 11)
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010051set(CMAKE_CXX_STANDARD 14)
52
53# Compile options
54add_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 Jonsson1c628992021-05-26 12:02:30 +020060# Compile defines
61add_compile_definitions(
62 "$<$<NOT:$<CONFIG:DEBUG>>:NDEBUG>")
63
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010064# Link options
65add_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
73add_compile_options(
74 -Wall
75 -Wextra
Kristofer Jonsson29467e02021-11-26 16:10:43 +010076
77 -Wcast-align
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010078 -Wdouble-promotion
Kristofer Jonsson29467e02021-11-26 16:10:43 +010079 -Wformat
80 -Wmissing-field-initializers
81 -Wnull-dereference
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010082 -Wredundant-decls
83 -Wshadow
Kristofer Jonsson29467e02021-11-26 16:10:43 +010084 -Wswitch-default
85 -Wunused
86)