blob: 2c0ebd0c044a8fc671a356fb9944dee502b787d7 [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
19if (NOT TARGET_CPU)
20 set(TARGET_CPU "cortex-m4")
21endif()
22
23set(CMAKE_SYSTEM_NAME Generic)
24set(CMAKE_C_COMPILER "arm-none-eabi-gcc")
25set(CMAKE_CXX_COMPILER "arm-none-eabi-g++")
26
27# Convert TARGET_CPU=Cortex-M33+nofp+nodsp into
28# - CMAKE_SYSTEM_PROCESSOR=cortex-m33
29# - TARGET_CPU_FEATURES=no-fp;no-dsp
30string(REPLACE "+" ";" TARGET_CPU_FEATURES ${TARGET_CPU})
31list(POP_FRONT TARGET_CPU_FEATURES CMAKE_SYSTEM_PROCESSOR)
32string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} CMAKE_SYSTEM_PROCESSOR)
33
34set(CMAKE_EXECUTABLE_SUFFIX ".elf")
35set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
36set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
37set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
38set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
39
40# Select C/C++ version
41set(CMAKE_C_STANDARD 99)
42set(CMAKE_CXX_STANDARD 14)
43
44# Compile options
45add_compile_options(
46 -mcpu=${TARGET_CPU}
47 -mthumb
48 "$<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables;-fno-rtti;-fno-exceptions>")
49
Kristofer Jonsson1c628992021-05-26 12:02:30 +020050# Compile defines
51add_compile_definitions(
52 "$<$<NOT:$<CONFIG:DEBUG>>:NDEBUG>")
53
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010054# Link options
55add_link_options(
56 -mcpu=${TARGET_CPU}
57 -mthumb
58 --specs=nosys.specs)
59
60# Set floating point unit
61if("${TARGET_CPU}" MATCHES "\\+fp")
62 set(FLOAT hard)
63elseif("${TARGET_CPU}" MATCHES "\\+nofp")
64 set(FLOAT soft)
65elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m33" OR
66 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m55")
67 set(FLOAT hard)
68else()
69 set(FLOAT soft)
70endif()
71
72if (FLOAT)
73 add_compile_options(-mfloat-abi=${FLOAT})
74 add_link_options(-mfloat-abi=${FLOAT})
75endif()
76
77# Compilation warnings
78add_compile_options(
79 -Wall
80 -Wextra
81 -Wsign-compare
82 -Wunused
83 -Wswitch-default
84# -Wformat
85 -Wdouble-promotion
86 -Wredundant-decls
87 -Wshadow
88# -Wcast-align
89 -Wnull-dereference
90 -Wno-format-extra-args
91 -Wno-unused-function
92 -Wno-unused-parameter
93 -Wno-unused-label
94 -Wno-missing-field-initializers
95 -Wno-return-type)