blob: afe57cdaae7c04b3833411588286cb0295e6f451 [file] [log] [blame]
Kristofer Jonsson6f4cb2a2020-08-17 16:57:43 +02001#
2# Copyright (c) 2019-2020 Arm Limited. All rights reserved.
3#
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")
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_C_STANDARD 99)
30set(CMAKE_CXX_STANDARD 11)
31
32# The system processor could for example be set to cortex-m33+nodsp+nofp.
33set(__CPU_COMPILE_TARGET ${CMAKE_SYSTEM_PROCESSOR})
34string(REPLACE "+" ";" __CPU_FEATURES ${__CPU_COMPILE_TARGET})
35list(POP_FRONT __CPU_FEATURES CMAKE_SYSTEM_PROCESSOR)
36
37string(FIND ${__CPU_COMPILE_TARGET} "+" __OFFSET)
38if(__OFFSET GREATER_EQUAL 0)
39 string(SUBSTRING ${__CPU_COMPILE_TARGET} ${__OFFSET} -1 CPU_FEATURES)
40endif()
41
42# Add -mcpu to the compile options to override the -mcpu the CMake toolchain adds
43add_compile_options(-mcpu=${__CPU_COMPILE_TARGET})
44
45# Link target
46set(__CPU_LINK_TARGET ${CMAKE_SYSTEM_PROCESSOR})
47if("nodsp" IN_LIST __CPU_FEATURES)
48 string(APPEND __CPU_LINK_TARGET ".no_dsp")
49endif()
50if("nofp" IN_LIST __CPU_FEATURES)
51 string(APPEND __CPU_LINK_TARGET ".no_fp")
52endif()
53
54if(CMAKE_SYSTEM_PROCESSOR STREQUAL "cortex-m55")
55 set(__CPU_LINK_TARGET 8.1-M.Main.dsp)
56endif()
57
58add_link_options(--cpu=${__CPU_LINK_TARGET})
59add_link_options(--lto --info common,debug,sizes,totals,veneers,unused --symbols --diag_suppress=L6439W)
60
61#
62# Compile options
63#
64
65add_compile_options(-Wall -Wextra
66 -Wsign-compare -Wunused -Wswitch-default -Wformat -Wdouble-promotion -Wredundant-decls -Wshadow -Wcast-align -Wnull-dereference
67 -Wno-format-extra-args -Wno-unused-function -Wno-unused-label -Wno-missing-field-initializers -Wno-return-type)
68add_compile_options(-fno-unwind-tables -fno-rtti -fno-exceptions)
69add_compile_options(-mthumb)
70add_compile_options("$<$<CONFIG:DEBUG>:-gdwarf-3>")