blob: ea95eef599c00c19a424902e775fff3107beb2ce [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 "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
50# Link options
51add_link_options(
52 -mcpu=${TARGET_CPU}
53 -mthumb
54 --specs=nosys.specs)
55
56# Set floating point unit
57if("${TARGET_CPU}" MATCHES "\\+fp")
58 set(FLOAT hard)
59elseif("${TARGET_CPU}" MATCHES "\\+nofp")
60 set(FLOAT soft)
61elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m33" OR
62 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m55")
63 set(FLOAT hard)
64else()
65 set(FLOAT soft)
66endif()
67
68if (FLOAT)
69 add_compile_options(-mfloat-abi=${FLOAT})
70 add_link_options(-mfloat-abi=${FLOAT})
71endif()
72
73# Compilation warnings
74add_compile_options(
75 -Wall
76 -Wextra
77 -Wsign-compare
78 -Wunused
79 -Wswitch-default
80# -Wformat
81 -Wdouble-promotion
82 -Wredundant-decls
83 -Wshadow
84# -Wcast-align
85 -Wnull-dereference
86 -Wno-format-extra-args
87 -Wno-unused-function
88 -Wno-unused-parameter
89 -Wno-unused-label
90 -Wno-missing-field-initializers
91 -Wno-return-type)