blob: 5ad7d0fd5573ce4761e6612faddbd6072c88a725 [file] [log] [blame]
Kristofer Jonsson43ce4912020-11-20 09:42:53 +01001#
Måns Nilsson24ea0402024-01-31 09:04:32 +01002# SPDX-FileCopyrightText: Copyright 2020-2022, 2024 Arm Limited and/or its affiliates <open-source-office@arm.com>
Kristofer Jonsson43ce4912020-11-20 09:42:53 +01003# SPDX-License-Identifier: Apache-2.0
4#
5# Licensed under the Apache License, Version 2.0 (the License); you may
6# not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an AS IS BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
Kristofer Jonssonec451552021-06-04 18:02:59 +020018set(TARGET_CPU "cortex-m4" CACHE STRING "Target CPU")
Ledion Dajaba6210b2022-06-21 12:06:59 +020019string(TOLOWER ${TARGET_CPU} CMAKE_SYSTEM_PROCESSOR)
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++")
Ledion Dajaba6210b2022-06-21 12:06:59 +020024set(CMAKE_ASM_COMPILER "arm-none-eabi-gcc")
25set(CMAKE_LINKER "arm-none-eabi-ld")
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010026
27set(CMAKE_EXECUTABLE_SUFFIX ".elf")
28set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
29set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
30set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
31set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
32
33# Select C/C++ version
Kristofer Jonssone2776742021-11-18 16:12:46 +010034set(CMAKE_C_STANDARD 11)
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010035set(CMAKE_CXX_STANDARD 14)
36
37# Compile options
38add_compile_options(
Måns Nilsson24ea0402024-01-31 09:04:32 +010039 -mcpu=${CMAKE_SYSTEM_PROCESSOR}
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010040 -mthumb
Davide Grohmann03e19e22021-08-11 13:35:14 +020041 "$<$<CONFIG:DEBUG>:-gdwarf-3>"
Davide Grohmann244a9b82022-08-15 17:11:54 +020042 "$<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables;-fno-rtti;-fno-exceptions>"
43 -fdata-sections
44 -ffunction-sections)
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010045
Kristofer Jonsson1c628992021-05-26 12:02:30 +020046# Compile defines
47add_compile_definitions(
48 "$<$<NOT:$<CONFIG:DEBUG>>:NDEBUG>")
49
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010050# Link options
51add_link_options(
Måns Nilsson24ea0402024-01-31 09:04:32 +010052 -mcpu=${CMAKE_SYSTEM_PROCESSOR}
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010053 -mthumb
54 --specs=nosys.specs)
55
56# Set floating point unit
Ledion Daja5f2200d2022-09-21 16:36:57 +020057if(CMAKE_SYSTEM_PROCESSOR MATCHES "\\+fp")
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010058 set(FLOAT hard)
Ledion Daja5f2200d2022-09-21 16:36:57 +020059elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "\\+nofp")
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010060 set(FLOAT soft)
Ledion Daja5f2200d2022-09-21 16:36:57 +020061elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m33(\\+|$)" OR
62 CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m55(\\+|$)" OR
63 CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m85(\\+|$)")
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010064 set(FLOAT hard)
Ledion Daja5f2200d2022-09-21 16:36:57 +020065elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m4(\\+|$)" OR
66 CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m7(\\+|$)")
Lior Dekel3e128622021-09-23 18:57:12 +030067 set(FLOAT hard)
68 set(FPU_CONFIG "fpv4-sp-d16")
69 add_compile_options(-mfpu=${FPU_CONFIG})
70 add_link_options(-mfpu=${FPU_CONFIG})
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010071else()
72 set(FLOAT soft)
73endif()
74
75if (FLOAT)
76 add_compile_options(-mfloat-abi=${FLOAT})
77 add_link_options(-mfloat-abi=${FLOAT})
78endif()
79
Davide Grohmann244a9b82022-08-15 17:11:54 +020080add_link_options(LINKER:--nmagic,--gc-sections)
81
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010082# Compilation warnings
83add_compile_options(
84 -Wall
85 -Wextra
Kristofer Jonsson29467e02021-11-26 16:10:43 +010086
87 -Wcast-align
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010088 -Wdouble-promotion
Kristofer Jonsson29467e02021-11-26 16:10:43 +010089 -Wformat
90 -Wmissing-field-initializers
91 -Wnull-dereference
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010092 -Wredundant-decls
93 -Wshadow
Kristofer Jonsson29467e02021-11-26 16:10:43 +010094 -Wswitch
95 -Wswitch-default
96 -Wunused
97
98 -Wno-redundant-decls
Davide Grohmanndd596042022-05-10 11:18:56 +020099
100 -Wno-psabi
Davide Grohmanna8832cc2022-05-06 16:35:16 +0200101)