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