blob: 61a8e599abc26500c8e1330186410a6e37619f56 [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 "armclang")
24set(CMAKE_CXX_COMPILER "armclang")
liodek01cbf1d6d2021-06-30 12:48:31 +030025set(CMAKE_ASM_COMPILER "armclang")
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010026set(CMAKE_LINKER "armlink")
27
Ledion Dajaba6210b2022-06-21 12:06:59 +020028set(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)
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010033
Ledion Dajaba6210b2022-06-21 12:06:59 +020034# 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 +020038# Link target
39string(REGEX MATCH "^cortex-m([0-9]+)([a-z]*)" __LINK_TARGET ${CMAKE_SYSTEM_PROCESSOR})
40if (CMAKE_SYSTEM_PROCESSOR MATCHES "nodsp")
41 string(APPEND __LINK_TARGET ".no_dsp")
42endif()
43if (CMAKE_SYSTEM_PROCESSOR MATCHES "nofp")
44 string(APPEND __LINK_TARGET ".no_fp")
45endif()
46
47if (CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m55")
48 set(__LINK_TARGET 8.1-M.Main.dsp)
49endif()
50
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010051# Compile options
52add_compile_options(
Ledion Dajaba6210b2022-06-21 12:06:59 +020053 -mcpu=${CMAKE_SYSTEM_PROCESSOR}
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010054 -mthumb
55 "$<$<CONFIG:DEBUG>:-gdwarf-3>"
56 "$<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables;-fno-rtti;-fno-exceptions>")
57
Kristofer Jonsson1c628992021-05-26 12:02:30 +020058# Compile defines
59add_compile_definitions(
60 "$<$<NOT:$<CONFIG:DEBUG>>:NDEBUG>")
61
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010062# Link options
63add_link_options(
64 --cpu=${__LINK_TARGET}
65 --lto
66 --info common,debug,sizes,totals,veneers,unused
67 --symbols
68 --diag_suppress=L6439W)
69
70# Compilation warnings
71add_compile_options(
72 -Wall
73 -Wextra
Kristofer Jonsson29467e02021-11-26 16:10:43 +010074
75 -Wcast-align
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010076 -Wdouble-promotion
Kristofer Jonsson29467e02021-11-26 16:10:43 +010077 -Wformat
78 -Wmissing-field-initializers
79 -Wnull-dereference
Kristofer Jonsson43ce4912020-11-20 09:42:53 +010080 -Wredundant-decls
81 -Wshadow
Kristofer Jonsson29467e02021-11-26 16:10:43 +010082 -Wswitch-default
83 -Wunused
84)