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