blob: 7d607eddda299f62853c37430320e2f409c6f4a5 [file] [log] [blame]
Kristofer Jonsson6f4cb2a2020-08-17 16:57:43 +02001#
Kristofer Jonsson1efcc3f2021-02-16 17:40:25 +01002# 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 "armclang")
26set(CMAKE_CXX_COMPILER "armclang")
Kristofer Jonsson1efcc3f2021-02-16 17:40:25 +010027set(CMAKE_ASM_COMPILER "armclang")
Kristofer Jonsson6f4cb2a2020-08-17 16:57:43 +020028set(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)")
29
30set(CMAKE_C_STANDARD 99)
31set(CMAKE_CXX_STANDARD 11)
32
33# The system processor could for example be set to cortex-m33+nodsp+nofp.
34set(__CPU_COMPILE_TARGET ${CMAKE_SYSTEM_PROCESSOR})
35string(REPLACE "+" ";" __CPU_FEATURES ${__CPU_COMPILE_TARGET})
36list(POP_FRONT __CPU_FEATURES CMAKE_SYSTEM_PROCESSOR)
37
38string(FIND ${__CPU_COMPILE_TARGET} "+" __OFFSET)
39if(__OFFSET GREATER_EQUAL 0)
40 string(SUBSTRING ${__CPU_COMPILE_TARGET} ${__OFFSET} -1 CPU_FEATURES)
41endif()
42
43# Add -mcpu to the compile options to override the -mcpu the CMake toolchain adds
Kristofer Jonsson1efcc3f2021-02-16 17:40:25 +010044add_compile_options(
45 -mcpu=${__CPU_COMPILE_TARGET}
46 "$<$<COMPILE_LANGUAGE:ASM>:-masm=auto;--target=arm-arm-none-eabi>")
Kristofer Jonsson6f4cb2a2020-08-17 16:57:43 +020047
Kristofer Jonssond273d8e2020-10-13 09:35:55 +020048# Set floating point unit
49if("${__CPU_COMPILE_TARGET}" MATCHES "\\+fp")
50 set(FLOAT hard)
51elseif("${__CPU_COMPILE_TARGET}" MATCHES "\\+nofp")
52 set(FLOAT soft)
53elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m33" OR
Kristofer Jonsson1efcc3f2021-02-16 17:40:25 +010054 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m4" OR
55 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m55" OR
56 "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m7")
Kristofer Jonssond273d8e2020-10-13 09:35:55 +020057 set(FLOAT hard)
58else()
59 set(FLOAT soft)
60endif()
61
62add_compile_options(-mfloat-abi=${FLOAT})
63#add_link_options(-mfloat-abi=${FLOAT})
64
Kristofer Jonsson6f4cb2a2020-08-17 16:57:43 +020065# Link target
66set(__CPU_LINK_TARGET ${CMAKE_SYSTEM_PROCESSOR})
67if("nodsp" IN_LIST __CPU_FEATURES)
68 string(APPEND __CPU_LINK_TARGET ".no_dsp")
69endif()
70if("nofp" IN_LIST __CPU_FEATURES)
71 string(APPEND __CPU_LINK_TARGET ".no_fp")
72endif()
73
74if(CMAKE_SYSTEM_PROCESSOR STREQUAL "cortex-m55")
75 set(__CPU_LINK_TARGET 8.1-M.Main.dsp)
76endif()
77
78add_link_options(--cpu=${__CPU_LINK_TARGET})
79add_link_options(--lto --info common,debug,sizes,totals,veneers,unused --symbols --diag_suppress=L6439W)
80
81#
82# Compile options
83#
84
85add_compile_options(-Wall -Wextra
Kristofer Jonsson1efcc3f2021-02-16 17:40:25 +010086 -Wsign-compare
87 -Wunused
88 -Wswitch-default
89 -Wformat
90 -Wdouble-promotion
91 -Wredundant-decls
92 -Wshadow
93 -Wcast-align
94 -Wnull-dereference
95 -Wno-deprecated-register
96 -Wno-format-extra-args
97 -Wno-missing-field-initializers
98 -Wno-unused-function
99 -Wno-unused-label
100 -Wno-unused-parameter
101 -Wno-return-type)
Kristofer Jonsson6f4cb2a2020-08-17 16:57:43 +0200102add_compile_options(-fno-unwind-tables -fno-rtti -fno-exceptions)
103add_compile_options(-mthumb)
104add_compile_options("$<$<CONFIG:DEBUG>:-gdwarf-3>")