blob: 25c510c79a78fe66738aa8f12a8b0ab290cef470 [file] [log] [blame]
Kristofer Jonsson43ce4912020-11-20 09:42:53 +01001#
Kristofer Jonsson1c628992021-05-26 12:02:30 +02002# Copyright (c) 2020-2021 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
45if (CMAKE_SYSTEM_PROCESSOR STREQUAL "cortex-m55")
46 set(__LINK_TARGET 8.1-M.Main.dsp)
47endif()
48
49# Define C/C++ standards
50set(CMAKE_C_STANDARD 99)
51set(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
76 -Wsign-compare
77 -Wunused
78 -Wswitch-default
79 -Wformat
80 -Wdouble-promotion
81 -Wredundant-decls
82 -Wshadow
83 -Wcast-align
84 -Wnull-dereference
85 -Wno-format-extra-args
86 -Wno-unused-function
87 -Wno-unused-label
88 -Wno-missing-field-initializers
89 -Wno-return-type)