@@ -64,27 +64,97 @@ message(STATUS "harucom_os version: ${HARUCOM_VERSION} (${HARUCOM_BUILD_DATE})")
6464# Initialise the Raspberry Pi Pico SDK
6565pico_sdk_init ()
6666
67- add_executable (harucom_os src/main.c )
67+ # --- PicoRuby ---
68+ set (PICORUBY_ROOT ${CMAKE_CURRENT_LIST_DIR } /lib/picoruby)
69+ set (PICORUBY_BUILD_CONFIG harucom-os-pico2)
70+
71+ # Build libmruby.a
72+ add_custom_command (
73+ OUTPUT ${PICORUBY_ROOT} /build/${PICORUBY_BUILD_CONFIG}/lib/libmruby.a
74+ COMMAND rake MRUBY_CONFIG=${CMAKE_CURRENT_LIST_DIR}/build_config/${PICORUBY_BUILD_CONFIG}.rb
75+ WORKING_DIRECTORY ${PICORUBY_ROOT}
76+ COMMENT "Building PicoRuby (libmruby.a)..."
77+ )
78+
79+ add_custom_target (build_picoruby
80+ DEPENDS ${PICORUBY_ROOT} /build/${PICORUBY_BUILD_CONFIG}/lib/libmruby.a
81+ )
82+
83+ add_library (mruby STATIC IMPORTED )
84+ set_target_properties (mruby PROPERTIES
85+ IMPORTED_LOCATION ${PICORUBY_ROOT} /build/${PICORUBY_BUILD_CONFIG} /lib/libmruby.a
86+ )
87+
88+ # --- Executable ---
89+ add_executable (harucom_os
90+ src/main.c
91+ src/hal.c
92+ ${PICORUBY_ROOT} /mrbgems/picoruby-gpio/ports/rp2040/gpio.c
93+ )
94+
95+ add_dependencies (harucom_os build_picoruby )
6896
6997pico_set_program_name (harucom_os "harucom_os" )
7098pico_set_program_version (harucom_os "${HARUCOM_VERSION} " )
7199
72- set_target_properties (harucom_os PROPERTIES
73- OUTPUT_NAME "harucom_os-${HARUCOM_VERSION} -${HARUCOM_BUILD_DATE} "
100+ set (HARUCOM_RELEASE_NAME "harucom_os-${HARUCOM_VERSION} -${HARUCOM_BUILD_DATE} " )
101+
102+ target_compile_definitions (harucom_os PRIVATE
103+ HARUCOM_VERSION= "${HARUCOM_VERSION} "
104+ HARUCOM_BUILD_DATE= "${HARUCOM_BUILD_DATE} "
105+ PICO_RP2350=1
106+ PICORB_VM_MRUBY=1
107+ MRB_INT64=1
108+ MRB_32BIT=1
109+ PICORB_ALLOC_ESTALLOC=1
110+ PICORB_ALLOC_ALIGN=8
111+ MRB_USE_CUSTOM_RO_DATA_P=1
112+ MRB_LINK_TIME_RO_DATA_P=1
113+ MRB_TICK_UNIT=1
114+ MRB_TIMESLICE_TICK_COUNT=10
115+ MRB_USE_TASK_SCHEDULER=1
116+ NO_CLOCK_GETTIME=1
117+ NDEBUG=1
118+ )
119+
120+ target_compile_options (harucom_os PRIVATE -fshort-enums )
121+
122+ target_include_directories (harucom_os PRIVATE
123+ ${CMAKE_CURRENT_LIST_DIR } /src
124+ ${PICORUBY_ROOT} /include
125+ ${PICORUBY_ROOT} /build/${PICORUBY_BUILD_CONFIG}/include
126+ ${PICORUBY_ROOT} /mrbgems/picoruby-mruby/lib/mruby/include
127+ ${PICORUBY_ROOT} /mrbgems/picoruby-mruby/include
128+ ${PICORUBY_ROOT} /mrbgems/mruby-compiler2/include
129+ ${PICORUBY_ROOT} /mrbgems/mruby-compiler2/lib/prism/include
130+ ${PICORUBY_ROOT} /mrbgems/picoruby-gpio/include
131+ ${PICORUBY_ROOT} /mrbgems/picoruby-mruby/lib/mruby/mrbgems/mruby-task/include
132+ ${PICORUBY_ROOT} /mrbgems/picoruby-machine/include
133+ ${PICORUBY_ROOT} /build/${PICORUBY_BUILD_CONFIG}/mrbgems
74134)
75135
76136# Enable UART output for debug
77137pico_enable_stdio_uart (harucom_os 1 )
78138pico_enable_stdio_usb (harucom_os 1 )
79139
80140target_link_libraries (harucom_os
81- pico_stdlib )
82-
83- target_include_directories ( harucom_os PRIVATE
84- ${ CMAKE_CURRENT_LIST_DIR } /src
141+ pico_stdlib
142+ hardware_timer
143+ hardware_gpio
144+ mruby
85145)
86146
87147string (APPEND CMAKE_EXE_LINKER_FLAGS "-Wl,--print-memory-usage" )
88148
89149pico_add_extra_outputs (harucom_os )
90150
151+ # Copy release artifacts with version-stamped names
152+ add_custom_command (TARGET harucom_os POST_BUILD
153+ COMMAND ${CMAKE_COMMAND } -E copy
154+ ${CMAKE_BINARY_DIR } /harucom_os.elf
155+ ${CMAKE_BINARY_DIR } /${HARUCOM_RELEASE_NAME}.elf
156+ COMMAND ${CMAKE_COMMAND } -E copy
157+ ${CMAKE_BINARY_DIR } /harucom_os.uf2
158+ ${CMAKE_BINARY_DIR } /${HARUCOM_RELEASE_NAME}.uf2
159+ COMMENT "Creating release files: ${HARUCOM_RELEASE_NAME} .{elf,uf2}"
160+ )
0 commit comments