-
Notifications
You must be signed in to change notification settings - Fork 17
/
CMakeLists.txt
216 lines (189 loc) · 7.57 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
cmake_minimum_required(VERSION 3.13)
## Define the board as pico_w. This includes everything in the firmware
## but the actual board detection is done at runtime
## https://forums.raspberrypi.com/viewtopic.php?t=336775
set(ENV{PICO_BOARD} "pico_w")
## We want our modified lwIP (mainly SVG-support in httpd and zopfli compression)
set(ENV{PICO_LWIP_PATH} ${CMAKE_CURRENT_LIST_DIR}/lib/lwip)
## pico_sdk_import.cmake is copied from
## https://github.com/raspberrypi/pico-sdk/blob/master/external/pico_sdk_import.cmake
include(${CMAKE_CURRENT_LIST_DIR}/pico_sdk_import.cmake)
## Give the baby a name. Will also be the name of the resulting binaries
project(rp2040-dmxsun)
## Init the pico-sdk. Will instruct the user what to do if deps are missing
pico_sdk_init()
## Get the targets for "npm install" and "npm run build"
include(${CMAKE_CURRENT_LIST_DIR}/wwwsrc/CMakeLists.txt)
## Command and target to build makefsdata
if(DEFINED ENV{CI})
message(STATUS "CI environment detected, using ZOPFLI compression")
set(BUILD_MAKEFSDATA_PARAMS -DMAKEFS_SUPPORT_DEFLATE_ZOPFLI=1 -I/usr/include/zopfli)
set(BUILD_MAKEFSDATA_LDPARAMS -lzopfli)
else()
message(STATUS "No CI environment detected, using faster zlib compression")
set(BUILD_MAKEFSDATA_PARAMS -DMAKEFS_SUPPORT_DEFLATE_ZLIB=1)
set(BUILD_MAKEFSDATA_LDPARAMS "")
endif()
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/makefsdata
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/lib/lwip/src/apps/http/makefsdata/makefsdata.c
COMMAND gcc -o makefsdata -DMAKEFS_SUPPORT_DEFLATE=1 ${BUILD_MAKEFSDATA_PARAMS} -I${CMAKE_CURRENT_LIST_DIR}/lib/lwip/src/include -I${CMAKE_CURRENT_LIST_DIR}/src ${CMAKE_CURRENT_LIST_DIR}/lib/lwip/src/apps/http/makefsdata/makefsdata.c -lz ${BUILD_MAKEFSDATA_LDPARAMS}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
add_custom_target(makefsdata
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/makefsdata
)
## Command and target to build fsdata.c from the webapp using makefsdata
if(DEFINED ENV{CI})
message(STATUS "CI environment detected, using ZOPFLI compression")
set(MAKEFSDATA_PARAMS -defl:400 -11)
else()
message(STATUS "No CI environment detected, using faster zlib compression")
set(MAKEFSDATA_PARAMS -defl:6 -11)
endif()
add_custom_command(
OUTPUT ${CMAKE_CURRENT_LIST_DIR}/src/fsdata.c
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/wwwsrc/build.md5
COMMAND ./makefsdata ${CMAKE_CURRENT_LIST_DIR}/wwwsrc/build ${MAKEFSDATA_PARAMS} -f:${CMAKE_CURRENT_LIST_DIR}/src/fsdata.c
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
add_custom_target(fsdata
DEPENDS webui_build makefsdata ${CMAKE_CURRENT_LIST_DIR}/src/fsdata.c
)
## Include the CMakeLists-files of (non-pico-sdk)-libraries we will be using
include(${CMAKE_CURRENT_LIST_DIR}/lib/RF24/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/lib/RF24Network/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/lib/RF24Mesh/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/lib/snappy/interfaceLibForPicoSDK.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/lib/libb64/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/lib/jsoncpp/interfaceLibForPicoSDK.cmake)
## Extra stuff from TinyUSB, that is not part of tinyusb_device library
## No longer included here since it has been copied to src/dhcpserver.c
#set(PICO_TINYUSB_PATH ${PICO_SDK_PATH}/lib/tinyusb)
#set(TINYUSB_LIBNETWORKING_SOURCES
# ${PICO_TINYUSB_PATH}/lib/networking/dhserver.c
#)
## I'd like to use LTO but it doesn't yet work
## https://github.com/raspberrypi/pico-sdk/issues/97
#add_compile_options(-flto -fno-fat-lto-objects -flto-partition=1to1 -fuse-ld=bfd -v)
#add_link_options(-Wl,-v -v -t -t)
## We want C++20 and will fail if not supported
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
## Get rid of some warnings that don't affect use since we build everything
## from source. See https://stackoverflow.com/a/48149400
add_compile_options(-Wno-psabi)
## Add our own C/C++ files here
## Sorted alphabetically
add_executable(${CMAKE_PROJECT_NAME}
${TINYUSB_LIBNETWORKING_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/src/boardconfig.cpp
${CMAKE_CURRENT_LIST_DIR}/src/crc_X25.c
${CMAKE_CURRENT_LIST_DIR}/src/dhcpdata.cpp
${CMAKE_CURRENT_LIST_DIR}/src/dhcpserver.c
${CMAKE_CURRENT_LIST_DIR}/src/dmxbuffer.cpp
${CMAKE_CURRENT_LIST_DIR}/src/edp.cpp
${CMAKE_CURRENT_LIST_DIR}/src/eth_cyw43.cpp
${CMAKE_CURRENT_LIST_DIR}/src/localdmx.cpp
${CMAKE_CURRENT_LIST_DIR}/src/log.cpp
${CMAKE_CURRENT_LIST_DIR}/src/main.cpp
${CMAKE_CURRENT_LIST_DIR}/src/oled_u8g2.cpp
${CMAKE_CURRENT_LIST_DIR}/src/pico_lwip_random.c
${CMAKE_CURRENT_LIST_DIR}/src/statusleds.cpp
${CMAKE_CURRENT_LIST_DIR}/src/stdio_usb.c
${CMAKE_CURRENT_LIST_DIR}/src/tusb_lwip_glue.c
${CMAKE_CURRENT_LIST_DIR}/src/udp_artnet.cpp
${CMAKE_CURRENT_LIST_DIR}/src/udp_e1_31.cpp
${CMAKE_CURRENT_LIST_DIR}/src/udp_edp.cpp
${CMAKE_CURRENT_LIST_DIR}/src/usb_descriptors.c
${CMAKE_CURRENT_LIST_DIR}/src/usb_generic.cpp
${CMAKE_CURRENT_LIST_DIR}/src/usb_EDP.cpp
${CMAKE_CURRENT_LIST_DIR}/src/usb_NodleU1.cpp
${CMAKE_CURRENT_LIST_DIR}/src/webserver.cpp
${CMAKE_CURRENT_LIST_DIR}/src/wireless.cpp
)
## Add our rp2040-PIO programs here
pico_generate_pio_header(${CMAKE_PROJECT_NAME}
${CMAKE_CURRENT_LIST_DIR}/src/tx16.pio
)
pico_generate_pio_header(${CMAKE_PROJECT_NAME}
${CMAKE_CURRENT_LIST_DIR}/src/ws2812.pio
)
## Define the SPI pins we use for the RF24 library
target_compile_definitions(${CMAKE_PROJECT_NAME}
PUBLIC PICO_DEFAULT_SPI_SCK_PIN=2
PUBLIC PICO_DEFAULT_SPI_TX_PIN=3
PUBLIC PICO_DEFAULT_SPI_RX_PIN=4
)
## Config for the RF24Network library
target_compile_definitions(${CMAKE_PROJECT_NAME}
PUBLIC MAX_PAYLOAD_SIZE=514
ENABLE_NETWORK_STATS
)
## Config for the RF24Mesh library
target_compile_definitions(${CMAKE_PROJECT_NAME}
PUBLIC MESH_DEFAULT_CHANNEL=120
PUBLIC MESH_RENEWAL_TIMEOUT=2000
PUBLIC MESH_MEM_ALLOC_SIZE=16
PUBLIC MESH_LOOKUP_TIMEOUT=250
PUBLIC MESH_WRITE_TIMEOUT=100
)
## Config for the jsoncpp library
target_compile_definitions(${CMAKE_PROJECT_NAME}
PUBLIC JSON_USE_EXCEPTION=0
)
## Config for the u8g2 OLED library
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/lib/u8g2 u8g2)
target_include_directories(${CMAKE_PROJECT_NAME} INTERFACE
u8g2/include
)
target_include_directories(u8g2 PUBLIC ${CMAKE_CURRENT_LIST_DIR}/lib/u8g2/cppsrc)
## LWIP works a little bit different than the other libraries since
## it ships its own FileList
set(LWIP_DIR ${CMAKE_CURRENT_LIST_DIR}/lib/lwip)
set (LWIP_INCLUDE_DIRS
"${LWIP_DIR}/src/include"
"${CMAKE_CURRENT_LIST_DIR}/src/"
)
include(${LWIP_DIR}/src/Filelists.cmake)
## Needed so tusb_config.h is found by the tinyUSB-library included in the pico-sdk
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
${LWIP_INCLUDE_DIRS}
${PICO_TINYUSB_PATH}/lib/networking
${CMAKE_CURRENT_LIST_DIR}
)
## Print memory usage percentages after linking
string(APPEND CMAKE_EXE_LINKER_FLAGS "-Wl,--print-memory-usage")
## Pull in all pico-sdk + non-pico-sdk libraries
## Sorted alphabetically
target_link_libraries(${CMAKE_PROJECT_NAME}
hardware_adc
hardware_dma
hardware_flash
hardware_i2c
hardware_irq
hardware_pio
hardware_spi
jsoncpp
libb64
lwipallapps
lwipcore
pico_cyw43_arch_lwip_poll
pico_lwip
pico_multicore
pico_stdlib
pico_time
pico_unique_id
RF24
RF24Network
RF24Mesh
snappy
tinyusb_board
tinyusb_device
u8g2
)
## Create map/bin/hex/uf2 file etc.
pico_add_extra_outputs(${CMAKE_PROJECT_NAME})
## Make sure fsdata is ready when lwip wants it
add_dependencies(lwipcore fsdata)
add_dependencies(lwipallapps fsdata)