blob: 182643fe888b69961489aa9c0a1102f7e51cd259 [file] [log] [blame]
Kristofer Jonsson43ce4912020-11-20 09:42:53 +01001#
Davide Grohmanna8832cc2022-05-06 16:35:16 +02002# Copyright (c) 2020-2022 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")
Ledion Dajaba6210b2022-06-21 12:06:59 +020020string(TOLOWER ${TARGET_CPU} CMAKE_SYSTEM_PROCESSOR)
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010021
22set(CMAKE_SYSTEM_NAME Generic)
23set(CMAKE_C_COMPILER "arm-none-eabi-gcc")
24set(CMAKE_CXX_COMPILER "arm-none-eabi-g++")
Ledion Dajaba6210b2022-06-21 12:06:59 +020025set(CMAKE_ASM_COMPILER "arm-none-eabi-gcc")
26set(CMAKE_LINKER "arm-none-eabi-ld")
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010027
28set(CMAKE_EXECUTABLE_SUFFIX ".elf")
29set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
30set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
31set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
32set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
33
34# Select C/C++ version
Kristofer Jonssone2776742021-11-18 16:12:46 +010035set(CMAKE_C_STANDARD 11)
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010036set(CMAKE_CXX_STANDARD 14)
37
Ledion Dajaba6210b2022-06-21 12:06:59 +020038set(GCC_CPU ${CMAKE_SYSTEM_PROCESSOR})
39string(REPLACE "cortex-m85" "cortex-m55" GCC_CPU ${GCC_CPU})
Davide Grohmanna8832cc2022-05-06 16:35:16 +020040
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010041# Compile options
42add_compile_options(
Davide Grohmanna8832cc2022-05-06 16:35:16 +020043 -mcpu=${GCC_CPU}
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010044 -mthumb
Davide Grohmann03e19e22021-08-11 13:35:14 +020045 "$<$<CONFIG:DEBUG>:-gdwarf-3>"
Davide Grohmann244a9b82022-08-15 17:11:54 +020046 "$<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables;-fno-rtti;-fno-exceptions>"
47 -fdata-sections
48 -ffunction-sections)
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010049
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(
Davide Grohmanna8832cc2022-05-06 16:35:16 +020056 -mcpu=${GCC_CPU}
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010057 -mthumb
58 --specs=nosys.specs)
59
60# Set floating point unit
Ledion Dajaba6210b2022-06-21 12:06:59 +020061if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "\\+fp")
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010062 set(FLOAT hard)
Ledion Dajaba6210b2022-06-21 12:06:59 +020063elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "\\+nofp")
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010064 set(FLOAT soft)
Ledion Dajaba6210b2022-06-21 12:06:59 +020065elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m33" OR
66 CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m55" OR
67 CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m85")
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010068 set(FLOAT hard)
Ledion Dajaba6210b2022-06-21 12:06:59 +020069elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m4" OR
70 CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m7")
Lior Dekel3e128622021-09-23 18:57:12 +030071 set(FLOAT hard)
72 set(FPU_CONFIG "fpv4-sp-d16")
73 add_compile_options(-mfpu=${FPU_CONFIG})
74 add_link_options(-mfpu=${FPU_CONFIG})
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010075else()
76 set(FLOAT soft)
77endif()
78
79if (FLOAT)
80 add_compile_options(-mfloat-abi=${FLOAT})
81 add_link_options(-mfloat-abi=${FLOAT})
82endif()
83
Davide Grohmann244a9b82022-08-15 17:11:54 +020084add_link_options(LINKER:--nmagic,--gc-sections)
85
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010086# Compilation warnings
87add_compile_options(
88 -Wall
89 -Wextra
Kristofer Jonsson29467e02021-11-26 16:10:43 +010090
91 -Wcast-align
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010092 -Wdouble-promotion
Kristofer Jonsson29467e02021-11-26 16:10:43 +010093 -Wformat
94 -Wmissing-field-initializers
95 -Wnull-dereference
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010096 -Wredundant-decls
97 -Wshadow
Kristofer Jonsson29467e02021-11-26 16:10:43 +010098 -Wswitch
99 -Wswitch-default
100 -Wunused
101
102 -Wno-redundant-decls
Davide Grohmanndd596042022-05-10 11:18:56 +0200103
104 -Wno-psabi
Davide Grohmanna8832cc2022-05-06 16:35:16 +0200105)