blob: c1f066b4aab29e69824a0361dd87ca2c282ba57a [file] [log] [blame]
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +01001#----------------------------------------------------------------------------
2# Copyright (c) 2021 Arm Limited. All rights reserved.
3# SPDX-License-Identifier: Apache-2.0
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://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,
13# WITHOUT 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# specify the cross compiler
18set(CMAKE_C_COMPILER armclang)
19set(CMAKE_CXX_COMPILER armclang)
20set(CMAKE_C_LINKER_PREFERENCE armlink)
21set(CMAKE_ASM_LINKER_PREFERENCE armlink)
22set(CMAKE_ASM_COMPILER armasm)
23set(CMAKE_ASM_COMPILER_AR armar)
24
25set(CMAKE_CROSSCOMPILING true)
26set(CMAKE_SYSTEM_NAME Generic)
27
Isabella Gottardic5d8bda2021-07-21 10:35:08 +010028set(MIN_ARM_CLANG_VERSION 6.15)
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010029
30# Skip compiler test execution
31set(CMAKE_C_COMPILER_WORKS 1)
32set(CMAKE_CXX_COMPILER_WORKS 1)
33set(PLATFORM_HAL 1)
34
35if (NOT DEFINED CMAKE_SYSTEM_PROCESSOR)
36 set(CMAKE_SYSTEM_PROCESSOR cortex-m55)
37endif()
38
39if (CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m55)
40 # Flags for cortex-m55
41 set(CPU_COMPILE_DEF CPU_CORTEX_M55)
42 set(CPU_NAME ${CMAKE_SYSTEM_PROCESSOR})
43 set(FLOAT_ABI hard)
44 set(ARM_MATH_DSP 1)
45 set(ARM_MATH_LOOPUNROLL 1)
Kshitij Sisodia3be26232021-10-29 12:29:06 +010046 set(CPU_LINK_OPT "--cpu=Cortex-M55")
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010047elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m33)
48 # Flags for cortex-m33 to go here
49endif()
50
51set(${CPU_COMPILE_DEF} 1)
52
53# Warning options
54add_compile_options(
55 -Wall
56 -Wextra
57 -Wvla)
58
59# General purpose compile options:
60add_compile_options(
61 -funsigned-char
62 -fno-function-sections
63 "$<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables;-fno-rtti;-fno-exceptions>")
64
65# Arch compile options:
66add_compile_options(
67 -mthumb
68 -mcpu=${CPU_NAME}
69 -mfloat-abi=${FLOAT_ABI}
70 --target=arm-arm-non-eabi
71 -mlittle-endian
72 -MD)
73
74# Compile definitions:
75add_compile_definitions(
76 PLATFORM_HAL=${PLATFORM_HAL}
77 ${CPU_COMPILE_DEF}=1
78 $<$<BOOL:${ARM_MATH_DSP}>:ARM_MATH_DSP>
79 $<$<BOOL:${ARM_MATH_LOOPUNROLL}>:ARM_MATH_LOOPUNROLL>)
80
81# Link options:
82add_link_options(${CPU_LINK_OPT})
83set(CMAKE_ASM_FLAGS "${CPU_LINK_OPT}")
84
85# Warnings to be ignored:
86# L6314W = No section matches pattern
87# L6439W = Multiply defined Global Symbol
88add_link_options(
89 --diag_suppress=L6439W,L6314W
90 --info sizes,totals,unused,veneers
91 --strict
92 --callgraph
93 --load_addr_map_info
94 --xref
95 "$<$<CONFIG:RELEASE>:--no_debug>")
96
97# Function to add a map file output for the linker to dump diagnostic information to.
98function(add_target_map_file TARGET_NAME MAP_FILE_PATH)
99 target_link_options(${TARGET_NAME} PUBLIC
100 --map --symbols --list=${MAP_FILE_PATH})
101endfunction()
102
103# Function to add linker option to use the chosen linker script (scatter file).
104function(add_linker_script SCRIPT_DIR SCRIPT_NAME)
105 set(LINKER_SCRIPT_PATH ${SCRIPT_DIR}/${SCRIPT_NAME}.sct
106 CACHE STRING "Linker script path")
107 if (NOT EXISTS ${LINKER_SCRIPT_PATH})
108 message(FATAL_ERROR "Scatter file not found: ${LINKER_SCRIPT_PATH}")
109 endif()
110 message(STATUS "Using linker script: ${LINKER_SCRIPT_PATH}")
111 add_link_options(--scatter=${LINKER_SCRIPT_PATH})
112endfunction()
113
114# Function to set the command to copy/extract contents from an elf
115# into a binary file.
116function(add_bin_generation_command)
117
118 set(multiValueArgs SECTION_PATTERNS OUTPUT_BIN_NAMES)
119 set(oneValueArgs TARGET_NAME OUTPUT_DIR AXF_PATH)
120 cmake_parse_arguments(PARSED "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
121
122 add_custom_command(TARGET ${PARSED_TARGET_NAME}
123 POST_BUILD
124 COMMAND fromelf --bin --output=${PARSED_OUTPUT_DIR}/
125 ${PARSED_AXF_PATH})
126
127endfunction()
128
129# Function to assert the compiler version
130function(enforce_compiler_version)
131 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${MIN_ARM_CLANG_VERSION})
132 message( FATAL_ERROR "Arm compiler version must be ${MIN_ARM_CLANG_VERSION} or greater to support ${CMAKE_SYSTEM_PROCESSOR} architecture." )
133 endif()
134endfunction()