-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
294 lines (257 loc) · 10.3 KB
/
Copy pathCMakeLists.txt
File metadata and controls
294 lines (257 loc) · 10.3 KB
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# Generated Cmake Pico project file
cmake_minimum_required(VERSION 3.13)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Initialise pico_sdk from installed location
# (note this can come from environment, CMake cache etc)
# == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work ==
if(WIN32)
set(USERHOME $ENV{USERPROFILE})
else()
set(USERHOME $ENV{HOME})
endif()
set(sdkVersion 2.2.0)
set(toolchainVersion 14_2_Rel1)
set(picotoolVersion 2.2.0-a4)
set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake)
if (EXISTS ${picoVscode})
include(${picoVscode})
endif()
# ====================================================================================
# Use pico-sdk from lib/pico-sdk (override pico-vscode.cmake)
set(PICO_SDK_PATH ${CMAKE_CURRENT_LIST_DIR}/lib/pico-sdk)
# Custom board
set(PICO_BOARD harucom_board CACHE STRING "Board type")
set(PICO_BOARD_HEADER_DIRS ${CMAKE_CURRENT_LIST_DIR}/include/boards)
set(PICO_PLATFORM rp2350-arm-s CACHE STRING "Platform")
# Firmware linker FLASH window. The chip holds 16 MB, but the firmware region
# is capped so it never reaches the dictionary at 0x600000 or the LittleFS
# filesystem at 0x800000. 6 MB ends exactly at 0x600000, giving the firmware
# the full span up to the dictionary. Overrides the RP2350 default of 4 MB
# (PICO_DEFAULT_FLASH_SIZE_BYTES in rp2350-arm-s.cmake). This only sizes the
# linker region; the runtime chip size stays 16 MB via PICO_FLASH_SIZE_BYTES
# in the board header.
set(PICO_FLASH_SIZE_BYTES "6 * 1024 * 1024")
# Pico-PIO-USB (must be set before pico_sdk_init)
set(PICO_PIO_USB_PATH ${CMAKE_CURRENT_LIST_DIR}/lib/Pico-PIO-USB)
# Pull in Raspberry Pi Pico SDK (must be before project)
include(pico_sdk_import.cmake)
project(harucom_os C CXX ASM)
# Version from git tags
find_package(Git)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --always
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE HARUCOM_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
endif()
if(NOT HARUCOM_VERSION)
set(HARUCOM_VERSION "unknown")
endif()
# Build date
execute_process(
COMMAND date +%Y%m%d
OUTPUT_VARIABLE HARUCOM_BUILD_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "harucom_os version: ${HARUCOM_VERSION} (${HARUCOM_BUILD_DATE})")
# Initialise the Raspberry Pi Pico SDK
pico_sdk_init()
# --- Ruby (for PicoRuby build) ---
find_package(Ruby QUIET)
if(NOT Ruby_EXECUTABLE)
message(FATAL_ERROR "Ruby interpreter not found.")
endif()
get_filename_component(_ruby_bindir "${Ruby_EXECUTABLE}" DIRECTORY)
find_program(RAKE rake HINTS "${_ruby_bindir}" REQUIRED)
execute_process(
COMMAND ${Ruby_EXECUTABLE} -e "puts Gem.path.join(':')"
OUTPUT_VARIABLE _gem_path
OUTPUT_STRIP_TRAILING_WHITESPACE)
get_filename_component(_toolchain_bindir "${CMAKE_C_COMPILER}" DIRECTORY)
# --- PicoRuby ---
set(PICORUBY_ROOT ${CMAKE_CURRENT_LIST_DIR}/lib/picoruby)
set(PICORUBY_BUILD_CONFIG harucom-os-pico2)
# Build libmruby.a (font headers are generated by mrbgem.rake during this step)
add_custom_command(
OUTPUT ${PICORUBY_ROOT}/build/${PICORUBY_BUILD_CONFIG}/lib/libmruby.a
COMMAND ${CMAKE_COMMAND} -E env
"PATH=${_toolchain_bindir}:${_ruby_bindir}:$ENV{PATH}"
"GEM_PATH=${_gem_path}"
${RAKE} MRUBY_CONFIG=${CMAKE_CURRENT_LIST_DIR}/build_config/${PICORUBY_BUILD_CONFIG}.rb
WORKING_DIRECTORY ${PICORUBY_ROOT}
COMMENT "Building PicoRuby (libmruby.a)..."
)
add_custom_target(build_picoruby
DEPENDS ${PICORUBY_ROOT}/build/${PICORUBY_BUILD_CONFIG}/lib/libmruby.a
)
add_library(mruby STATIC IMPORTED)
set_target_properties(mruby PROPERTIES
IMPORTED_LOCATION ${PICORUBY_ROOT}/build/${PICORUBY_BUILD_CONFIG}/lib/libmruby.a
)
# --- DVI driver library (timing-critical, always -O2) ---
set(UNI2JIS_TABLE_C ${PICORUBY_ROOT}/build/${PICORUBY_BUILD_CONFIG}/mrbgems/picoruby-dvi/include/uni2jis_table.c)
set_source_files_properties(${UNI2JIS_TABLE_C} PROPERTIES GENERATED TRUE)
add_library(picoruby-dvi
mrbgems/picoruby-dvi/ports/rp2350/dvi_clock.c
mrbgems/picoruby-dvi/ports/rp2350/dvi_output.c
mrbgems/picoruby-dvi/src/dvi_graphics_draw.c
${UNI2JIS_TABLE_C}
)
add_dependencies(picoruby-dvi build_picoruby)
target_include_directories(picoruby-dvi PUBLIC
mrbgems/picoruby-dvi/include
mrbgems/picoruby-dvi/src
mrbgems/picoruby-dvi/ports/rp2350
${PICORUBY_ROOT}/build/${PICORUBY_BUILD_CONFIG}/mrbgems/picoruby-dvi/include
)
target_link_libraries(picoruby-dvi pico_stdlib hardware_clocks hardware_dma)
target_compile_options(picoruby-dvi PRIVATE -O2)
# target_compile_definitions(picoruby-dvi PUBLIC DVI_DIAGNOSTICS)
# --- PWM Audio library ---
add_library(picoruby-pwm-audio
mrbgems/picoruby-pwm-audio/src/pwm_audio.c
mrbgems/picoruby-pwm-audio/src/qoa_decoder.c
mrbgems/picoruby-pwm-audio/src/byte_source.c
mrbgems/picoruby-pwm-audio/ports/rp2350/pwm_audio_port.c
)
add_dependencies(picoruby-pwm-audio build_picoruby)
target_include_directories(picoruby-pwm-audio PUBLIC
mrbgems/picoruby-pwm-audio/include
)
target_link_libraries(picoruby-pwm-audio pico_stdlib hardware_pwm hardware_dma hardware_clocks pico_time)
# --- DMX library ---
add_library(picoruby-dmx
mrbgems/picoruby-dmx/src/dmx.c
mrbgems/picoruby-dmx/ports/rp2350/dmx_port.c
)
add_dependencies(picoruby-dmx build_picoruby)
target_include_directories(picoruby-dmx PUBLIC
mrbgems/picoruby-dmx/include
)
target_link_libraries(picoruby-dmx pico_stdlib hardware_uart hardware_dma pico_time)
# --- Ruby scripts (rootfs/ -> ruby_scripts.h) ---
# Track all rootfs files (Ruby, YAML, images, etc.) so that edits
# retrigger gen_ruby_scripts.rb.
file(GLOB_RECURSE ROOTFS_FILES ${CMAKE_SOURCE_DIR}/rootfs/*)
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/ruby_scripts.h
COMMAND ${Ruby_EXECUTABLE} ${CMAKE_SOURCE_DIR}/scripts/gen_ruby_scripts.rb
${CMAKE_SOURCE_DIR}/rootfs
${CMAKE_BINARY_DIR}/ruby_scripts.h
DEPENDS ${ROOTFS_FILES} ${CMAKE_SOURCE_DIR}/scripts/gen_ruby_scripts.rb
COMMENT "Generating ruby_scripts.h from rootfs/"
)
add_custom_target(ruby_scripts_gen DEPENDS ${CMAKE_BINARY_DIR}/ruby_scripts.h)
# --- Executable ---
add_executable(harucom_os
src/main.c
src/hal_task.c
src/hal_machine.c
src/psram.c
src/init_rootfs.c
ports/picoruby-littlefs/flash_hal.c
src/platform.c
src/env.c
${PICORUBY_ROOT}/mrbgems/picoruby-rng/ports/rp2040/rng.c
${PICORUBY_ROOT}/mrbgems/picoruby-gpio/ports/rp2040/gpio.c
${PICORUBY_ROOT}/mrbgems/picoruby-adc/ports/rp2040/adc.c
${PICORUBY_ROOT}/mrbgems/picoruby-io-console/ports/rp2040/io-console.c
${PICORUBY_ROOT}/mrbgems/picoruby-watchdog/ports/rp2040/watchdog.c
mrbgems/picoruby-usb-host/ports/rp2350/usb_host.c
mrbgems/harucom-os-dict/ports/rp2350/dict_region.c
mrbgems/picoruby-flash-file/ports/rp2350/flash_file.c
)
add_dependencies(harucom_os build_picoruby ruby_scripts_gen)
pico_set_program_name(harucom_os "harucom_os")
pico_set_program_version(harucom_os "${HARUCOM_VERSION}")
set(HARUCOM_RELEASE_NAME "harucom_os-${HARUCOM_VERSION}-${HARUCOM_BUILD_DATE}")
target_compile_definitions(harucom_os PRIVATE
HARUCOM_VERSION="${HARUCOM_VERSION}"
HARUCOM_BUILD_DATE="${HARUCOM_BUILD_DATE}"
PICO_RP2350=1
PICORB_VM_MRUBY=1
MRB_INT64=1
MRB_32BIT=1
PICORB_ALLOC_ESTALLOC=1
PICORB_ALLOC_ALIGN=8
MRB_USE_CUSTOM_RO_DATA_P=1
MRB_LINK_TIME_RO_DATA_P=1
MRB_TICK_UNIT=1
MRB_TIMESLICE_TICK_COUNT=10
MRB_USE_TASK_SCHEDULER=1
NO_CLOCK_GETTIME=1
NDEBUG=1
BOARD_TUH_RHPORT=1
)
target_compile_options(harucom_os PRIVATE -fshort-enums)
target_include_directories(harucom_os PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src
${CMAKE_CURRENT_LIST_DIR}/include
${CMAKE_BINARY_DIR}
${PICORUBY_ROOT}/include
${PICORUBY_ROOT}/build/${PICORUBY_BUILD_CONFIG}/include
${PICORUBY_ROOT}/mrbgems/picoruby-mruby/lib/mruby/include
${PICORUBY_ROOT}/mrbgems/picoruby-mruby/include
${PICORUBY_ROOT}/mrbgems/mruby-compiler2/include
${PICORUBY_ROOT}/mrbgems/mruby-compiler2/lib/prism/include
${PICORUBY_ROOT}/mrbgems/picoruby-gpio/include
${PICORUBY_ROOT}/mrbgems/picoruby-mruby/lib/mruby/mrbgems/mruby-task/include
${PICORUBY_ROOT}/mrbgems/picoruby-machine/include
${PICORUBY_ROOT}/mrbgems/picoruby-io-console/include
${PICORUBY_ROOT}/mrbgems/picoruby-watchdog/include
${PICORUBY_ROOT}/mrbgems/picoruby-require/include
${PICORUBY_ROOT}/mrbgems/picoruby-env/include
${PICORUBY_ROOT}/mrbgems/picoruby-time/include
${PICORUBY_ROOT}/mrbgems/picoruby-littlefs/include
${PICORUBY_ROOT}/mrbgems/picoruby-littlefs/lib/littlefs
${PICORUBY_ROOT}/build/${PICORUBY_BUILD_CONFIG}/mrbgems
${PICORUBY_ROOT}/mrbgems/picoruby-adc/include
${CMAKE_CURRENT_LIST_DIR}/mrbgems/picoruby-usb-host/include
${CMAKE_CURRENT_LIST_DIR}/mrbgems/harucom-os-dict/include
${CMAKE_CURRENT_LIST_DIR}/mrbgems/picoruby-pwm-audio/include
${CMAKE_CURRENT_LIST_DIR}/mrbgems/picoruby-flash-file/include
${CMAKE_CURRENT_LIST_DIR}/mrbgems/picoruby-dmx/include
${PICORUBY_ROOT}/build/${PICORUBY_BUILD_CONFIG}/mrbgems/picoruby-dvi/include
)
# Enable UART output for debug (USB stdio disabled for USB host mode)
pico_enable_stdio_uart(harucom_os 1)
pico_enable_stdio_usb(harucom_os 0)
target_link_libraries(harucom_os
pico_stdlib
pico_multicore
pico_unique_id
pico_aon_timer
hardware_timer
hardware_adc
hardware_gpio
hardware_uart
hardware_flash
hardware_sync
hardware_watchdog
tinyusb_host
tinyusb_pico_pio_usb
mruby
picoruby-dvi
picoruby-pwm-audio
picoruby-dmx
)
# Core 0 needs 32 KB stack for mruby compiler (mrc_load_string_cxt).
# Default __STACK_SIZE is 0x800 (2 KB), which is insufficient.
target_link_options(harucom_os PRIVATE -Wl,--defsym=__STACK_SIZE=0x8000)
string(APPEND CMAKE_EXE_LINKER_FLAGS "-Wl,--print-memory-usage")
pico_add_extra_outputs(harucom_os)
# Copy release artifacts with version-stamped names
add_custom_command(TARGET harucom_os POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_BINARY_DIR}/harucom_os.elf
${CMAKE_BINARY_DIR}/${HARUCOM_RELEASE_NAME}.elf
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_BINARY_DIR}/harucom_os.uf2
${CMAKE_BINARY_DIR}/${HARUCOM_RELEASE_NAME}.uf2
COMMENT "Creating release files: ${HARUCOM_RELEASE_NAME}.{elf,uf2}"
)