-
Notifications
You must be signed in to change notification settings - Fork 38
/
CMakeLists.txt
230 lines (199 loc) · 7.29 KB
/
CMakeLists.txt
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# Copyright 2021-2022,2024 HPMicro
# SPDX-License-Identifier: BSD-3-Clause
cmake_minimum_required(VERSION 3.13)
cmake_policy(SET CMP0079 NEW)
project(hpm_sdk)
add_library(${HPM_SDK_LIB} STATIC "")
target_link_libraries(${HPM_SDK_LIB} PUBLIC ${HPM_SDK_LIB_ITF})
add_library(${HPM_SDK_GCC_LIB} STATIC "")
target_link_libraries(${HPM_SDK_GCC_LIB} PUBLIC ${HPM_SDK_GCC_LIB_ITF} ${HPM_SDK_LIB_ITF})
target_link_libraries(${HPM_SDK_LIB} PUBLIC ${HPM_SDK_GCC_LIB_ITF})
if("${TOOLCHAIN_VARIANT}" STREQUAL "nds-gcc")
target_link_libraries(${HPM_SDK_LIB} PUBLIC ${HPM_SDK_NDSGCC_LIB_ITF})
elseif("${TOOLCHAIN_VARIANT}" STREQUAL "zcc")
target_link_libraries(${HPM_SDK_LIB} PUBLIC ${HPM_SDK_ZCC_LIB_ITF})
target_link_libraries(${HPM_SDK_GCC_LIB} PUBLIC ${HPM_SDK_ZCC_LIB_ITF})
endif()
if(flash_size)
sdk_linker_global_symbols("_flash_size=${flash_size}")
endif()
if(extram_size)
sdk_linker_global_symbols("_extram_size=${extram_size}")
endif()
if(NOT ${CMAKE_BUILD_TYPE} STREQUAL "")
string(TOLOWER ${CMAKE_BUILD_TYPE} build_type)
string(FIND ${build_type} "release" found)
if (${found} GREATER_EQUAL 0)
sdk_compile_options("-O3")
else()
sdk_compile_options("-g")
endif()
endif()
string(TOLOWER ${HPM_BUILD_TYPE} hpm_build_type)
SET(FLASH_XIP 0)
SET(FLASH_SDRAM_XIP 0)
SET(LINK_TO_FLASH 0)
if(NOT DEFINED INCLUDE_BOOTHEADER)
SET(INCLUDE_BOOTHEADER 0)
endif()
string(FIND ${hpm_build_type} "flash_" found)
if(${found} GREATER_EQUAL 0)
string(FIND ${hpm_build_type} "flash_xip" found)
if(${found} GREATER_EQUAL 0)
set(FLASH_XIP 1)
set(LINK_TO_FLASH 1)
set(INCLUDE_BOOTHEADER 1)
sdk_compile_definitions("-DFLASH_XIP=1")
endif()
string(FIND ${hpm_build_type} "flash_sdram_xip" found)
if(${found} GREATER_EQUAL 0)
set(FLASH_SDRAM_XIP 1)
set(LINK_TO_FLASH 1)
set(INCLUDE_BOOTHEADER 1)
sdk_compile_definitions("-DFLASH_XIP=1")
sdk_compile_definitions("-DINIT_EXT_RAM_FOR_DATA=1")
endif()
string(FIND ${hpm_build_type} "flash_uf2" found)
if(${found} GREATER_EQUAL 0)
set(FLASH_UF2 1)
set(LINK_TO_FLASH 1)
set(EXCLUDE_BOOTHEADER 1)
sdk_compile_definitions("-DFLASH_UF2=1")
endif()
string(FIND ${hpm_build_type} "flash_sdram_uf2" found)
if(${found} GREATER_EQUAL 0)
set(FLASH_SDRAM_UF2 1)
set(LINK_TO_FLASH 1)
set(EXCLUDE_BOOTHEADER 1)
sdk_compile_definitions("-DFLASH_UF2=1")
sdk_compile_definitions("-DINIT_EXT_RAM_FOR_DATA=1")
endif()
if(DEFINED EXCLUDE_BOOTHEADER)
if (${EXCLUDE_BOOTHEADER})
set(INCLUDE_BOOTHEADER 0)
endif()
endif()
endif()
string(FIND ${hpm_build_type} "sec_core_img" found)
if(${found} GREATER_EQUAL 0)
set(BUILD_FOR_SECONDARY_CORE true CACHE INTERNAL "")
set(GEN_SEC_CORE_IMG_C_ARRAY true PARENT_SCOPE)
endif()
set(USE_PRESET_FLASH_LINKER 0)
if(DEFINED CUSTOM_GCC_LINKER_FILE)
set(USE_CUSTOM_LINKER 1)
if(NOT IS_ABSOLUTE ${CUSTOM_GCC_LINKER_FILE})
message(FATAL_ERROR "Custom ld script has to be absolute path not relative: ${CUSTOM_GCC_LINKER_FILE}")
else()
set(LINKER_SCRIPT ${CUSTOM_GCC_LINKER_FILE})
endif()
elseif(DEFINED USE_LINKER_TEMPLATE)
set(USE_CUSTOM_LINKER 1)
set(LINKER_SCRIPT ${PROJECT_BINARY_DIR}/linker.cmd)
else()
set(USE_PRESET_FLASH_LINKER 1)
endif()
if(${EXCLUDE_SDK_STARTUP})
set(USE_CUSTOM_STARTUP 1)
endif()
if(DEFINED CUSTOM_GCC_STARTUP_FILE)
set(USE_CUSTOM_STARTUP 1)
sdk_gcc_src(${CUSTOM_GCC_STARTUP_FILE})
endif()
if(DEFINED CUSTOM_SES_STARTUP_FILE)
set(USE_CUSTOM_STARTUP 1)
sdk_ses_src(${CUSTOM_SES_STARTUP_FILE})
endif()
if(DEFINED CUSTOM_IAR_STARTUP_FILE)
set(USE_CUSTOM_STARTUP 1)
sdk_iar_src(${CUSTOM_IAR_STARTUP_FILE})
endif()
sdk_sys_inc(${SYSROOT_DIR}/include)
# parse module list file provided in soc folder, it will decide which modules to be enabled under drivers folder
import_soc_modules(soc/${HPM_SOC_SERIES}/${HPM_SOC}/soc_modules.list)
add_subdirectory(arch)
add_subdirectory(boards)
add_subdirectory(soc)
add_subdirectory(drivers)
add_subdirectory(utils)
add_subdirectory(components)
add_subdirectory(middleware)
if(DEFINED USE_LINKER_TEMPLATE)
set(linker_script_dep DEPFILE ${PROJECT_BINARY_DIR}/${LINKER_SCRIPT}.dep)
get_directory_property(compile_defs COMPILE_DEFINITIONS)
foreach(def ${compile_defs})
list(APPEND all_defs -D${def})
endforeach()
get_filename_component(base_name ${CMAKE_CURRENT_BINARY_DIR} NAME)
set(LINKER_TARGET linker)
add_custom_command(
OUTPUT ${LINKER_SCRIPT}
DEPENDS
${HPM_SDK_BASE}/soc/${HPM_SOC_SERIES}/${HPM_SOC}/toolchains/gcc/linker.ld
${linker_script_dep}
COMMAND ${CMAKE_C_COMPILER}
-x assembler-with-cpp
-MD -MF ${LINKER_SCRIPT}.dep -MT ${base_name}/${LINKER_SCRIPT}
${all_defs}
-E ${HPM_SDK_BASE}/soc/${HPM_SOC_SERIES}/${HPM_SOC}/toolchains/gcc/linker.ld
-P
-o ${LINKER_SCRIPT}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
VERBATIM)
add_custom_target(${LINKER_TARGET} DEPENDS ${LINKER_SCRIPT})
endif()
if(NOT EXISTS ${LINKER_SCRIPT})
message(FATAL_ERROR "Can not locate GNU ld linker script: ${LINKER_SCRIPT}")
else()
message(STATUS "GNU ld linker script: ${LINKER_SCRIPT}")
endif()
sdk_ld_options("-T ${LINKER_SCRIPT}")
set(generated_file_path "${PROJECT_BINARY_DIR}/generated")
# generate SDK version file
execute_process(
COMMAND ${CMAKE_COMMAND} -DHPM_SDK_BASE=${HPM_SDK_BASE}
-DOUT_FILE=${generated_file_path}/include/hpm_sdk_version.h
-DSDKVERSION=${SDKVERSION}
-DSDK_VERSION_NUMBER=${SDK_VERSION_NUMBER}
-DSDK_VERSION_MAJOR=${SDK_VERSION_MAJOR}
-DSDK_VERSION_MINOR=${SDK_VERSION_MINOR}
-DSDK_PATCHLEVEL=${SDK_PATCHLEVEL}
-DSDK_VERSION_STRING=${SDK_VERSION_STRING}
-P ${HPM_SDK_BASE}/cmake/gen_version_h.cmake
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
sdk_inc(${generated_file_path}/include)
set_target_properties(${APP_ELF_NAME} PROPERTIES LINK_DEPENDS ${LINKER_SCRIPT})
if(NOT DEFINED HPM_SDK_LD_NO_WHOLE_SDK)
set(HPM_SDK_LD_NO_WHOLE_SDK 0)
endif()
set(HPM_SDK_WHOLE_ARCHIVE_OPT "-Wl,--whole-archive")
if(${HPM_SDK_LD_NO_WHOLE_SDK})
set(HPM_SDK_WHOLE_ARCHIVE_OPT "")
endif()
if("${TOOLCHAIN_VARIANT}" STREQUAL "nds-gcc")
target_link_libraries(${HPM_SDK_LIB} PUBLIC ${HPM_SDK_NDSGCC_LIB_ITF})
target_link_libraries(${APP_ELF_NAME}
"-Wl,-Map=${EXECUTABLE_OUTPUT_PATH}/${APP_MAP_NAME}"
${HPM_SDK_WHOLE_ARCHIVE_OPT}
${HPM_SDK_NDSGCC_LIB_ITF}
${HPM_SDK_GCC_LIB} ${HPM_SDK_GCC_LIB_ITF}
${HPM_SDK_LIB} ${HPM_SDK_LIB_ITF} app
"-Wl,--no-whole-archive")
elseif("${TOOLCHAIN_VARIANT}" STREQUAL "zcc")
target_link_libraries(${HPM_SDK_LIB} PUBLIC ${HPM_SDK_ZCC_LIB_ITF})
target_link_libraries(${APP_ELF_NAME}
"-Wl,-Map=${EXECUTABLE_OUTPUT_PATH}/${APP_MAP_NAME}"
${HPM_SDK_WHOLE_ARCHIVE_OPT}
${HPM_SDK_ZCC_LIB_ITF}
${HPM_SDK_GCC_LIB} ${HPM_SDK_GCC_LIB_ITF}
${HPM_SDK_LIB} ${HPM_SDK_LIB_ITF} app
"-Wl,--no-whole-archive")
else()
target_link_libraries(${APP_ELF_NAME}
"-Wl,-Map=${EXECUTABLE_OUTPUT_PATH}/${APP_MAP_NAME}"
${HPM_SDK_WHOLE_ARCHIVE_OPT}
${HPM_SDK_GCC_LIB} ${HPM_SDK_GCC_LIB_ITF}
${HPM_SDK_LIB} ${HPM_SDK_LIB_ITF} app
"-Wl,--no-whole-archive")
endif()