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