blob: 4852db166e79ad3f4dfccfd65b694a7d1ab09473 [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
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)
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
ayamas0115f80702021-11-18 14:22:23 +000041 set(CPU_ID M55)
42 set(CPU_COMPILE_DEF CPU_CORTEX_${CPU_ID})
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010043 set(CPU_NAME ${CMAKE_SYSTEM_PROCESSOR})
ayamas0115f80702021-11-18 14:22:23 +000044 set(ARM_CPU "ARMC${CPU_ID}")
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010045 set(FLOAT_ABI hard)
46 set(ARM_MATH_DSP 1)
47 set(ARM_MATH_LOOPUNROLL 1)
ayamas0115f80702021-11-18 14:22:23 +000048 set(CPU_HEADER_FILE "${ARM_CPU}.h")
49 set(CPU_LINK_OPT "--cpu=Cortex-${CPU_ID}")
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010050elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m33)
51 # Flags for cortex-m33 to go here
52endif()
53
54set(${CPU_COMPILE_DEF} 1)
55
56# Warning options
57add_compile_options(
58 -Wall
59 -Wextra
60 -Wvla)
61
62# General purpose compile options:
63add_compile_options(
64 -funsigned-char
65 -fno-function-sections
66 "$<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables;-fno-rtti;-fno-exceptions>")
67
68# Arch compile options:
69add_compile_options(
70 -mthumb
71 -mcpu=${CPU_NAME}
72 -mfloat-abi=${FLOAT_ABI}
73 --target=arm-arm-non-eabi
74 -mlittle-endian
75 -MD)
76
77# Compile definitions:
78add_compile_definitions(
79 PLATFORM_HAL=${PLATFORM_HAL}
ayamas0115f80702021-11-18 14:22:23 +000080 CPU_HEADER_FILE=\"${CPU_HEADER_FILE}\"
81 $<$<BOOL:${CPU_COMPILE_DEF}>:${CPU_COMPILE_DEF}>
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010082 $<$<BOOL:${ARM_MATH_DSP}>:ARM_MATH_DSP>
83 $<$<BOOL:${ARM_MATH_LOOPUNROLL}>:ARM_MATH_LOOPUNROLL>)
84
85# Link options:
86add_link_options(${CPU_LINK_OPT})
87set(CMAKE_ASM_FLAGS "${CPU_LINK_OPT}")
88
89# Warnings to be ignored:
90# L6314W = No section matches pattern
91# L6439W = Multiply defined Global Symbol
92add_link_options(
93 --diag_suppress=L6439W,L6314W
94 --info sizes,totals,unused,veneers
95 --strict
96 --callgraph
97 --load_addr_map_info
98 --xref
99 "$<$<CONFIG:RELEASE>:--no_debug>")
100
101# Function to add a map file output for the linker to dump diagnostic information to.
102function(add_target_map_file TARGET_NAME MAP_FILE_PATH)
103 target_link_options(${TARGET_NAME} PUBLIC
104 --map --symbols --list=${MAP_FILE_PATH})
105endfunction()
106
107# Function to add linker option to use the chosen linker script (scatter file).
108function(add_linker_script SCRIPT_DIR SCRIPT_NAME)
109 set(LINKER_SCRIPT_PATH ${SCRIPT_DIR}/${SCRIPT_NAME}.sct
110 CACHE STRING "Linker script path")
111 if (NOT EXISTS ${LINKER_SCRIPT_PATH})
112 message(FATAL_ERROR "Scatter file not found: ${LINKER_SCRIPT_PATH}")
113 endif()
114 message(STATUS "Using linker script: ${LINKER_SCRIPT_PATH}")
115 add_link_options(--scatter=${LINKER_SCRIPT_PATH})
116endfunction()
117
118# Function to set the command to copy/extract contents from an elf
119# into a binary file.
120function(add_bin_generation_command)
121
122 set(multiValueArgs SECTION_PATTERNS OUTPUT_BIN_NAMES)
123 set(oneValueArgs TARGET_NAME OUTPUT_DIR AXF_PATH)
124 cmake_parse_arguments(PARSED "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
125
126 add_custom_command(TARGET ${PARSED_TARGET_NAME}
127 POST_BUILD
128 COMMAND fromelf --bin --output=${PARSED_OUTPUT_DIR}/
129 ${PARSED_AXF_PATH})
130
131endfunction()
132
133# Function to assert the compiler version
134function(enforce_compiler_version)
135 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${MIN_ARM_CLANG_VERSION})
Kshitij Sisodiaee98bd62022-01-17 13:38:54 +0000136 message( FATAL_ERROR "Arm compiler version must be ${MIN_ARM_CLANG_VERSION} or greater." )
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100137 endif()
138endfunction()