-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
224 lines (197 loc) · 6.89 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
cmake_minimum_required(VERSION 3.24)
#set(CMAKE_VERBOSE_MAKEFILE ON)
include(pico_sdk_import.cmake)
include(pico_extras_import.cmake)
# Initialize the SDK
pico_sdk_init()
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 (R2P2_VERSION ${CMAKE_VERSION_NUMBER})
set (R2P2_BUILDDATE ${CMAKE_BUILDDATE})
set (R2P2_REVISION ${CMAKE_REVISION})
if(DEFINED ENV{PICORUBY_MSC_FLASH})
set (MSC_NAME FLASH_MSC)
add_definitions(-DPICORUBY_MSC_FLASH)
remove_definitions(-DPICORUBY_MSC_SD)
elseif(DEFINED ENV{PICORUBY_MSC_SD})
set (MSC_NAME SD_MSC)
add_definitions(-DPICORUBY_MSC_SD)
remove_definitions(-DPICORUBY_MSC_FLASH)
else()
message(FATAL_ERROR "PICORUBY_MSC_xxxx is not defined.")
endif()
if((DEFINED ENV{PICO_WIFI}) AND DEFINED ENV{PICO_BLE})
message(FATAL_ERROR "Both BLE and WiFi cannot be enabled for Pico W")
elseif(DEFINED ENV{PICO_WIFI})
set(PICO_BOARD pico_w)
set(R2P2_NAME R2P2_WIFI)
set(BUILD_CONFIG r2p2_wifi-cortex-m0plus)
set(BUILD_DIR build_pico_wifi)
elseif(DEFINED ENV{PICO_BLE})
set(PICO_BOARD pico_w)
set(R2P2_NAME R2P2_BLE)
set(BUILD_CONFIG r2p2_ble-cortex-m0plus)
set(BUILD_DIR build_pico_ble)
elseif(DEFINED ENV{PICO2})
set(PICO_BOARD pico2)
set(R2P2_NAME R2P2_PICO2)
set(BUILD_CONFIG r2p2-cortex-m33)
set(BUILD_DIR build_pico2)
else()
set(R2P2_NAME R2P2)
set(BUILD_CONFIG r2p2-cortex-m0plus)
set(BUILD_DIR build_pico)
endif()
project("${R2P2_NAME}-${MSC_NAME}-${R2P2_VERSION}-${R2P2_BUILDDATE}-${R2P2_REVISION}")
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
)
add_definitions(
# These defines should not contradict defines in
# picoruby/build_config/${BUILD_CONFIG}.rb
-DMRC_CUSTOM_ALLOC
-DMRBC_REQUIRE_32BIT_ALIGNMENT
-DMRBC_CONVERT_CRLF
-DMRBC_USE_FLOAT=2
-DMRBC_USE_MATH
-DMRBC_TICK_UNIT=1
-DMRBC_TIMESLICE_TICK_COUNT=10
)
if(DEFINED ENV{PICORUBY_DEBUG})
add_definitions(
-DPICORUBY_DEBUG
)
else()
add_definitions(
-DNDEBUG
)
endif()
if(DEFINED ENV{PICO_WIFI})
add_definitions(
-DUSE_WIFI
)
endif()
file(GLOB SRCS src/*.c)
set(SOURCE_FILES
${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
)
# only used in BLE build
if(DEFINED ENV{PICO_BLE})
list(APPEND SOURCE_FILES
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-cyw43/ports/rp2040/cyw43.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-ble/ports/rp2040/ble.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-ble/ports/rp2040/ble_peripheral.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-ble/ports/rp2040/ble_central.c
)
endif()
# only used in WiFi build
if(DEFINED ENV{PICO_WIFI})
list(APPEND SOURCE_FILES
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-cyw43/ports/rp2040/cyw43.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-net/ports/rp2040/common.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-net/ports/rp2040/dns.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-net/ports/rp2040/tcp.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-net/ports/rp2040/udp.c
)
endif()
add_executable(${PROJECT_NAME}
${SOURCE_FILES}
)
set(PICORBC ${CMAKE_SOURCE_DIR}/lib/picoruby/bin/picorbc)
add_custom_target(mrbdir ALL
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/${BUILD_DIR}/mrb
)
set(RUBY_FILES r2p2_task usb_task)
add_dependencies(${PROJECT_NAME}
mrbdir
${RUBY_FILES}
)
foreach(rb ${RUBY_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)
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/${BUILD_DIR}/mrb
${CMAKE_CURRENT_LIST_DIR}/include
)
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_flash
hardware_adc
hardware_uart
hardware_i2c
hardware_spi
hardware_pwm
pico_runtime
hardware_sleep
hardware_rtc
mruby
)
# btstack is used in BLE build
if(DEFINED ENV{PICO_BLE})
target_link_libraries(${PROJECT_NAME} PRIVATE
pico_btstack_ble
pico_btstack_cyw43
)
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-ble/include
)
endif()
if(DEFINED ENV{PICO_WIFI})
# these are used only in WiFi build
target_link_libraries(${PROJECT_NAME} PRIVATE
pico_cyw43_arch_lwip_threadsafe_background
pico_lwip_mbedtls
pico_mbedtls
)
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/include-net
)
#else()
# # Even the BLE build needs a pico_cyw43_arch, only in a different flavor
# target_link_libraries(${PROJECT_NAME} PRIVATE
# pico_cyw43_arch_none
# )
endif()
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}
${PICO_SDK_PATH}/src/rp2_common/pico_stdio_usb/include
${CMAKE_SOURCE_DIR}/lib/picoruby/include/hal_no_impl
${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/build/${BUILD_CONFIG}/mrbgems
${CMAKE_SOURCE_DIR}/lib/picoruby/build/repos/${BUILD_CONFIG}/mruby-compiler2/include
)
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
)