blob: 964b9e38442037a44eaa0b5adbdf9817674ce309 [file] [log] [blame]
Kristofer Jonsson6f4cb2a2020-08-17 16:57:43 +02001#
Kristofer Jonsson34c8bc92021-06-22 12:22:40 +02002# Copyright (c) 2019-2021 Arm Limited. All rights reserved.
Kristofer Jonsson6f4cb2a2020-08-17 16:57:43 +02003#
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 (__TOOLCHAIN_LOADED)
20 return()
21endif()
22set(__TOOLCHAIN_LOADED TRUE)
23
24set(CMAKE_SYSTEM_NAME Generic)
25set(CMAKE_C_COMPILER "arm-none-eabi-gcc")
26set(CMAKE_CXX_COMPILER "arm-none-eabi-g++")
27set(CMAKE_SYSTEM_PROCESSOR "cortex-m33+nodsp" CACHE STRING "Select Cortex-M architure. (cortex-m0, cortex-m3, cortex-m33, cortex-m4, cortex-m55, cortex-m7, etc)")
28
29set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
30
31SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
32SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
33SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
34
35set(CMAKE_C_STANDARD 99)
Per Åstrand5014a442020-11-05 11:24:09 +010036set(CMAKE_CXX_STANDARD 14)
Kristofer Jonsson6f4cb2a2020-08-17 16:57:43 +020037
38# The system processor could for example be set to cortex-m33+nodsp+nofp.
39set(__CPU_COMPILE_TARGET ${CMAKE_SYSTEM_PROCESSOR})
40string(REPLACE "+" ";" __CPU_FEATURES ${__CPU_COMPILE_TARGET})
41list(POP_FRONT __CPU_FEATURES CMAKE_SYSTEM_PROCESSOR)
42
43string(FIND ${__CPU_COMPILE_TARGET} "+" __OFFSET)
44if(__OFFSET GREATER_EQUAL 0)
45 string(SUBSTRING ${__CPU_COMPILE_TARGET} ${__OFFSET} -1 CPU_FEATURES)
46endif()
47
48# Add -mcpu to the compile options to override the -mcpu the CMake toolchain adds
49add_compile_options(-mcpu=${__CPU_COMPILE_TARGET})
50
51# Set floating point unit
52if("${__CPU_COMPILE_TARGET}" MATCHES "\\+fp")
53 set(FLOAT hard)
54elseif("${__CPU_COMPILE_TARGET}" MATCHES "\\+nofp")
55 set(FLOAT soft)
56elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m33" OR
57 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m55")
58 set(FLOAT hard)
59else()
60 set(FLOAT soft)
61endif()
62
63add_compile_options(-mfloat-abi=${FLOAT})
64add_link_options(-mfloat-abi=${FLOAT})
65
66# Link target
67add_link_options(-mcpu=${__CPU_COMPILE_TARGET})
Kristofer Jonsson6f4cb2a2020-08-17 16:57:43 +020068
69#
70# Compile options
71#
72set(cxx_flags "-fno-unwind-tables;-fno-rtti;-fno-exceptions")
73
74add_compile_options("-Wall;-Wextra;-Wsign-compare;-Wunused;-Wswitch-default;-Wformat;\
75-Wdouble-promotion;-Wredundant-decls;-Wshadow;-Wcast-align;-Wnull-dereference;\
76-Wno-format-extra-args;-Wno-unused-function;-Wno-unused-label;\
77-Wno-missing-field-initializers;-Wno-return-type"
78 "$<$<COMPILE_LANGUAGE:CXX>:${cxx_flags}>"
79)
80