-
Notifications
You must be signed in to change notification settings - Fork 53
/
CMakeLists.txt
188 lines (164 loc) · 5.8 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
cmake_minimum_required(VERSION 3.24)
# initialize the SDK based on PICO_SDK_PATH
# note: this must happen before project()
include(pico_sdk_import.cmake)
include(pico_extras_import.cmake)
#####################################################
# project specific configuration from here
add_definitions(
-DMRBC_REQUIRE_32BIT_ALIGNMENT
-DMAX_REGS_SIZE=256
-DMAX_VM_COUNT=255
-DMAX_SYMBOLS_COUNT=1800
-DMRBC_CONVERT_CRLF
-DMRBC_USE_MATH
-DMRBC_USE_FLOAT=2
-DNO_CLOCK_GETTIME=1
)
execute_process (COMMAND date +%Y%m%d OUTPUT_VARIABLE CMAKE_BUILDDATE OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process (COMMAND git rev-parse --short HEAD OUTPUT_VARIABLE CMAKE_REVISION OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process (COMMAND git describe --tags --abbrev=0 OUTPUT_VARIABLE CMAKE_VERSION_NUMBER OUTPUT_STRIP_TRAILING_WHITESPACE)
set (PRK_VERSION ${CMAKE_VERSION_NUMBER})
set (PRK_BUILDDATE ${CMAKE_BUILDDATE})
set (PRK_REVISION ${CMAKE_REVISION})
configure_file ("${CMAKE_SOURCE_DIR}/include/version.h.in" "${CMAKE_SOURCE_DIR}/include/version.h")
if(DEFINED ENV{PICORUBY_NO_MSC})
set (MSC_NAME NO_MSC)
add_definitions(-DPICORUBY_NO_MSC)
elseif(DEFINED ENV{PICORUBY_MSC_SD})
set (MSC_NAME MSC_SD)
add_definitions(-DPICORUBY_MSC_SD)
else()
set (MSC_NAME MSC_FLASH)
add_definitions(-DPICORUBY_MSC_FLASH)
endif()
if(DEFINED ENV{PICORUBY_SQLITE3})
set (MSC_NAME ${MSC_NAME}-SQLITE3)
add_definitions(-DPICORUBY_SQLITE3)
endif()
if(DEFINED ENV{PICO2})
set(PICO_BOARD pico2)
set(R2P2_NAME R2P2_PICO2)
set(BUILD_CONFIG prk_firmware-cortex-m33)
set(BUILD_DIR build_pico2)
add_compile_options(
-mcpu=cortex-m33
#-march=armv8-m.main+fp+dsp
#-mabi=aapcs-linux
#-mfloat-abi=softfp
-fno-strict-aliasing
-fno-unroll-loops
-mslow-flash-data
)
else()
set(R2P2_NAME R2P2)
set(BUILD_CONFIG prk_firmware-cortex-m0plus)
set(BUILD_DIR build_pico)
endif()
project("prk_firmware-${PICO_BOARD}-${MSC_NAME}-${PRK_VERSION}-${PRK_BUILDDATE}-${PRK_REVISION}")
# Initializing the Raspberry Pi Pico SDK should happen after project created
pico_sdk_init()
add_compile_options(-Wall
# int != int32_t as far as the compiler is concerned because gcc has int32_t as long int
-Wno-format
-Wno-unused-function
-Wno-maybe-uninitialized
-fshort-enums
)
file(GLOB SRCS src/*.c)
add_executable(${PROJECT_NAME}
${SRCS}
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-filesystem-fat/ports/rp2040/flash_disk.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-filesystem-fat/ports/rp2040/sd_disk.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-filesystem-fat/ports/rp2040/msc_disk.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-gpio/ports/rp2040/gpio.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-i2c/ports/rp2040/i2c.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-spi/ports/rp2040/spi.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-adc/ports/rp2040/adc.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-uart/ports/rp2040/uart.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-pwm/ports/rp2040/pwm.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-machine/ports/rp2040/machine.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-io-console/ports/rp2040/io-console.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-watchdog/ports/rp2040/watchdog.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-rng/ports/rp2040/rng.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-env/ports/rp2040/env.c
)
set(PICORBC ${CMAKE_SOURCE_DIR}/lib/picoruby/bin/picorbc)
pico_generate_pio_header(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/src/ws2812.pio)
pico_generate_pio_header(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/src/sounder.pio)
set(RBC ${CMAKE_CURRENT_SOURCE_DIR}/lib/picoruby/bin/picorbc)
#set(RBC RBENV_VERSION=mruby-3.2.0 mrbc) # In case of PicoRuby compiler enbugged 😵
# Ruby
if(DEFINED ENV{PICORUBY_NO_MSC})
add_dependencies(${PROJECT_NAME}
keymap
)
add_custom_target(keymap
COMMAND ${RBC} -Bkeymap -o ./keymap.c ../keymap.rb
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
target_include_directories(${PROJECT_NAME} PRIVATE
${PROJECT_BINARY_DIR}
)
endif()
add_custom_target(mrbdir ALL
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/${BUILD_DIR}/mrb
)
set(RUBY_TASK_FILES
usb_task
)
foreach(rb ${RUBY_TASK_FILES})
add_custom_target(${rb}
COMMAND ${PICORBC} -B${rb}
-o${CMAKE_SOURCE_DIR}/${BUILD_DIR}/mrb/${rb}.c
${CMAKE_SOURCE_DIR}/mrblib/${rb}.rb
)
endforeach(rb)
add_dependencies(${PROJECT_NAME}
mrbdir
${RUBY_TASK_FILES}
)
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/tinyusb
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-machine/include
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-mrubyc/lib/mrubyc/src
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-filesystem-fat/lib/ff14b/source
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems
${CMAKE_SOURCE_DIR}/lib/picoruby/build/${BUILD_CONFIG}/mrbgems
${CMAKE_SOURCE_DIR}/lib/picoruby/build/repos/${BUILD_CONFIG}/mruby-compiler2/include
${CMAKE_SOURCE_DIR}/${BUILD_DIR}/mrb
)
target_link_directories(${PROJECT_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/lib/picoruby/build/${BUILD_CONFIG}/lib
)
target_link_libraries(${PROJECT_NAME} PRIVATE
pico_stdlib
pico_bootsel_via_double_reset
tinyusb_device
tinyusb_board
hardware_pio
hardware_flash
hardware_adc
hardware_uart
hardware_dma
hardware_sync
hardware_irq
hardware_i2c
hardware_spi
hardware_pwm
mruby
)
# Workaround for Pico2
if(NOT DEFINED ENV{PICO2})
target_link_libraries(${PROJECT_NAME} PRIVATE
hardware_sleep
)
endif()
# create map/bin/hex/uf2 file in addition to ELF.
pico_add_extra_outputs(${PROJECT_NAME})
add_custom_command(
TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND gzip -kf ${PROJECT_NAME}.uf2
COMMAND zip -r ${PROJECT_NAME}.uf2.zip ${PROJECT_NAME}.uf2
)