blob: 065395b40ae329f7e3fb193b3c020c8cb6efa993 [file] [log] [blame]
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +01001#----------------------------------------------------------------------------
Isabella Gottardic64f5062022-01-21 15:27:13 +00002# Copyright (c) 2021 - 2022 Arm Limited. All rights reserved.
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +01003# 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
Kshitij Sisodiaee98bd62022-01-17 13:38:54 +000028set(MIN_ARM_CLANG_VERSION 6.16)
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)
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010033
34if (NOT DEFINED CMAKE_SYSTEM_PROCESSOR)
35 set(CMAKE_SYSTEM_PROCESSOR cortex-m55)
36endif()
37
38if (CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m55)
39 # Flags for cortex-m55
ayamas0115f80702021-11-18 14:22:23 +000040 set(CPU_ID M55)
41 set(CPU_COMPILE_DEF CPU_CORTEX_${CPU_ID})
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010042 set(CPU_NAME ${CMAKE_SYSTEM_PROCESSOR})
ayamas0115f80702021-11-18 14:22:23 +000043 set(ARM_CPU "ARMC${CPU_ID}")
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010044 set(FLOAT_ABI hard)
45 set(ARM_MATH_DSP 1)
46 set(ARM_MATH_LOOPUNROLL 1)
ayamas0115f80702021-11-18 14:22:23 +000047 set(CPU_HEADER_FILE "${ARM_CPU}.h")
48 set(CPU_LINK_OPT "--cpu=Cortex-${CPU_ID}")
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010049elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m33)
50 # Flags for cortex-m33 to go here
51endif()
52
53set(${CPU_COMPILE_DEF} 1)
54
55# Warning options
56add_compile_options(
57 -Wall
58 -Wextra
59 -Wvla)
60
61# General purpose compile options:
62add_compile_options(
63 -funsigned-char
64 -fno-function-sections
65 "$<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables;-fno-rtti;-fno-exceptions>")
66
67# Arch compile options:
68add_compile_options(
69 -mthumb
70 -mcpu=${CPU_NAME}
71 -mfloat-abi=${FLOAT_ABI}
72 --target=arm-arm-non-eabi
73 -mlittle-endian
74 -MD)
75
76# Compile definitions:
77add_compile_definitions(
ayamas0115f80702021-11-18 14:22:23 +000078 CPU_HEADER_FILE=\"${CPU_HEADER_FILE}\"
79 $<$<BOOL:${CPU_COMPILE_DEF}>:${CPU_COMPILE_DEF}>
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010080 $<$<BOOL:${ARM_MATH_DSP}>:ARM_MATH_DSP>
81 $<$<BOOL:${ARM_MATH_LOOPUNROLL}>:ARM_MATH_LOOPUNROLL>)
82
83# Link options:
84add_link_options(${CPU_LINK_OPT})
85set(CMAKE_ASM_FLAGS "${CPU_LINK_OPT}")
86
87# Warnings to be ignored:
88# L6314W = No section matches pattern
89# L6439W = Multiply defined Global Symbol
90add_link_options(
91 --diag_suppress=L6439W,L6314W
92 --info sizes,totals,unused,veneers
93 --strict
94 --callgraph
95 --load_addr_map_info
96 --xref
97 "$<$<CONFIG:RELEASE>:--no_debug>")
98
99# Function to add a map file output for the linker to dump diagnostic information to.
100function(add_target_map_file TARGET_NAME MAP_FILE_PATH)
101 target_link_options(${TARGET_NAME} PUBLIC
102 --map --symbols --list=${MAP_FILE_PATH})
103endfunction()
104
105# Function to add linker option to use the chosen linker script (scatter file).
alexander31ae9f02022-02-10 16:15:54 +0000106function(add_linker_script TARGET_NAME SCRIPT_DIR SCRIPT_NAME)
107 set(LINKER_SCRIPT_PATH ${SCRIPT_DIR}/${SCRIPT_NAME}.sct)
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100108 if (NOT EXISTS ${LINKER_SCRIPT_PATH})
109 message(FATAL_ERROR "Scatter file not found: ${LINKER_SCRIPT_PATH}")
110 endif()
111 message(STATUS "Using linker script: ${LINKER_SCRIPT_PATH}")
alexander31ae9f02022-02-10 16:15:54 +0000112 target_link_options(${TARGET_NAME} PUBLIC
113 --scatter=${LINKER_SCRIPT_PATH})
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100114endfunction()
115
116# Function to set the command to copy/extract contents from an elf
117# into a binary file.
118function(add_bin_generation_command)
119
120 set(multiValueArgs SECTION_PATTERNS OUTPUT_BIN_NAMES)
121 set(oneValueArgs TARGET_NAME OUTPUT_DIR AXF_PATH)
122 cmake_parse_arguments(PARSED "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
123
124 add_custom_command(TARGET ${PARSED_TARGET_NAME}
125 POST_BUILD
126 COMMAND fromelf --bin --output=${PARSED_OUTPUT_DIR}/
127 ${PARSED_AXF_PATH})
128
129endfunction()
130
131# Function to assert the compiler version
132function(enforce_compiler_version)
133 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${MIN_ARM_CLANG_VERSION})
Kshitij Sisodiaee98bd62022-01-17 13:38:54 +0000134 message( FATAL_ERROR "Arm compiler version must be ${MIN_ARM_CLANG_VERSION} or greater." )
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100135 endif()
136endfunction()