-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoolchain-gnu.cmake
executable file
·161 lines (137 loc) · 4.96 KB
/
toolchain-gnu.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#/* Copyright (C) 2022 Alif Semiconductor - All Rights Reserved.
# * Use, distribution and modification of this code is permitted under the
# * terms stated in the Alif Semiconductor Software License Agreement
# *
# * You should have received a copy of the Alif Semiconductor Software
# * License Agreement with this file. If not, please write to:
# * [email protected], or visit: https://alifsemi.com/license
# *
# */
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
SET(CMAKE_LINKER arm-none-eabi-ld)
set(CMAKE_CROSSCOMPILING true)
set(CMAKE_SYSTEM_NAME Generic)
if ("${ENSEMBLE_CORE}" STREQUAL "M55_HE" OR "${ENSEMBLE_CORE}" STREQUAL "M55_HP")
set(CMAKE_SYSTEM_PROCESSOR "cortex-m55")
set(CMAKE_C_FLAGS "-mcpu=cortex-m55")
set(CMAKE_CXX_FLAGS "-mcpu=cortex-m55")
set(CMAKE_ASM_CPU_FLAG cortex-m55)
set(CPU_COMPILE_DEF CPU_CORTEX_M55)
endif()
if ("${ENSEMBLE_CORE}" STREQUAL "A32")
set(CMAKE_SYSTEM_PROCESSOR "cortex-a32")
set(CMAKE_C_FLAGS "-mcpu=cortex-a32")
set(CMAKE_CXX_FLAGS "-mcpu=cortex-a32")
set(CMAKE_ASM_FLAGS "-mcpu=cortex-a32")
endif()
set(CPU_NAME ${CMAKE_SYSTEM_PROCESSOR})
# Generate .elf
set(BINARY_EXTENSION ".elf")
find_program(CMAKE_C_COMPILER arm-none-eabi-gcc)
find_program(CMAKE_CXX_COMPILER arm-none-eabi-g++)
if (DEFINED XIP)
set(ALIF_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/linker/gcc_${ENSEMBLE_CORE}_MRAM.ld)
set (XIP ${XIP}) # To avoid CMake warning about unused XIP variable
else()
# Default is TCM
set(ALIF_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/linker/gcc_${ENSEMBLE_CORE}_TCM.ld)
endif()
set(CMAKE_C_FLAGS_DEBUG "-O0 -g" CACHE STRING "Flags used by the C compiler during DEBUG builds.")
set(CMAKE_C_FLAGS_MINSIZEREL "-Os -g -DNDEBUG" CACHE STRING "Flags used by the C compiler during MINSIZEREL builds.")
set(CMAKE_C_FLAGS_RELEASE "-O2 -g -DNDEBUG" CACHE STRING "Flags used by the C compiler during RELEASE builds.")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g" CACHE STRING "Flags used by the CXX compiler during DEBUG builds.")
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -g -DNDEBUG" CACHE STRING "Flags used by the CXX compiler during MINSIZEREL builds.")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -g -DNDEBUG" CACHE STRING "Flags used by the CXX compiler during RELEASE builds.")
add_compile_options(
-mfloat-abi=hard
)
if ("${ENSEMBLE_CORE}" STREQUAL "M55_HE" OR "${ENSEMBLE_CORE}" STREQUAL "M55_HP")
add_compile_options(
-mthumb
-mlittle-endian
)
endif()
if ("${ENSEMBLE_CORE}" STREQUAL "A32")
add_compile_options(
-mfpu=neon-fp-armv8
-marm
-mno-unaligned-access
)
endif()
add_compile_options(
-Wall
-Wno-unused-function
-Wextra
-Werror-implicit-function-declaration
-Wvla
-Wno-error=cpp
-c
-fdata-sections
-ffunction-sections
-fshort-enums
-funsigned-char
$<$<COMPILE_LANGUAGE:C>:-std=c99>
$<$<COMPILE_LANGUAGE:CXX>:-std=c++11>
-MD
)
macro(set_warnings_as_errors target)
target_compile_options(${target} PRIVATE
-Werror
)
endmacro()
macro(set_werror_implicit_function_declaration target)
target_compile_options(${target} PRIVATE
-Werror-implicit-function-declaration
)
endmacro()
macro(add_elf_to_bin_phase target)
add_custom_command(TARGET ${target} POST_BUILD
COMMAND arm-none-eabi-objcopy -O binary ${target}.elf ${target}.bin
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
endmacro()
macro(add_linker_file_to_target target linker_file)
message(STATUS "Using ld file: ${linker_file} for target ${target}")
add_library(${target}_linkerfile OBJECT)
target_link_options(${target}
PRIVATE
-T $<TARGET_OBJECTS:${target}_linkerfile>
"SHELL:-Xlinker -Map=bin/${target}.map"
)
target_sources(${target}_linkerfile
PRIVATE
${linker_file}
)
set_source_files_properties(${linker_file}
PROPERTIES
LANGUAGE C
)
add_dependencies(${target}
${target}_linkerfile
)
set_target_properties(${target} PROPERTIES LINK_DEPENDS $<TARGET_OBJECTS:${target}_linkerfile>)
target_link_libraries(${target}_linkerfile
rte_interface
ensemblecmsis_interface
)
target_compile_options(${target}_linkerfile
PRIVATE
-E
-P
-xc
)
# This is a hack to get math (m) library in as the last one on the list.
# This is needed because Driver_I2S.c uses round method from math library.
target_link_libraries(ensemblecmsis
PRIVATE
m
)
endmacro()
add_link_options(
-mthumb
-mfloat-abi=hard
-mlittle-endian
-specs=nosys.specs
-Wl,--print-memory-usage
)