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