-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists-template.txt
50 lines (42 loc) · 1.41 KB
/
CMakeLists-template.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
cmake_minimum_required(VERSION 3.10)
# Set your SDK ROOT here
set(WCH_SDK_ROOT "../../ch573-sdk")
set(WCH_DRIVER_ROOT "${WCH_SDK_ROOT}/StdPeriphDriver")
get_filename_component(LINKER_SCRIPT "${WCH_SDK_ROOT}/ld/Link.ld" REALPATH)
set(CMAKE_TOOLCHAIN_FILE "${WCH_SDK_ROOT}/riscv.cmake")
# set the project name
project(test LANGUAGES C ASM)
set(CMAKE_SYSTEM_PROCESSOR "rv32imac_zicsr")
# specify the C++ standard
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os -Wall -ffunction-sections")
set(TARGET main)
# add the executable
add_executable(${TARGET}.elf
${TARGET}.c
${WCH_DRIVER_ROOT}/CH57x_gpio.c
${WCH_DRIVER_ROOT}/CH57x_sys.c
${WCH_SDK_ROOT}/RVMSIS/core_riscv.c
${WCH_SDK_ROOT}/Startup/startup_CH573.s
)
target_include_directories(${TARGET}.elf PRIVATE
../include/
${WCH_DRIVER_ROOT}/inc
${WCH_SDK_ROOT}/RVMSIS
)
target_link_options(${TARGET}.elf PRIVATE
"--specs=nosys.specs"
"--specs=nano.specs"
"-nostartfiles"
"-fno-exceptions"
"-Xlinker"
"-T" "${LINKER_SCRIPT}"
"-Wl,-Map=${TARGET}.map"
"-Wl,--print-memory-usage"
)
# Post processing command to create a hex file
add_custom_command(TARGET ${TARGET}.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O ihex ${TARGET}.elf ${TARGET}.hex
COMMENT "Invoking: Hexdump")
add_custom_command(TARGET ${TARGET}.elf POST_BUILD
COMMAND ${CROSS_COMPILE}size ${TARGET}.elf
COMMENT "Invoking: filesize")