-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
688 lines (633 loc) · 22.3 KB
/
CMakeLists.txt
File metadata and controls
688 lines (633 loc) · 22.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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
####
# USBSID-Pico is a RPi Pico/PicoW (RP2040) & Pico2/Pico2W (RP2350) based board
# for interfacing one or two MOS SID chips and/or hardware SID emulators over
# (WEB)USB with your computer, phone or ASID supporting player
#
# CMakeLists.txt
# This file is part of USBSID-Pico (https://github.com/LouDnl/USBSID-Pico)
# File author: LouD
#
# Copyright (c) 2024-2026 LouD
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
####
### Cmake minimum version
cmake_minimum_required(VERSION 3.17)
### Project magic sprinkles
set(PROJECT_NAME usbsidpico)
set(PROJECT_MANUFACTURER "LouD")
set(PRODUCT_STRING "USBSID-Pico")
string(TIMESTAMP MAGIC_SMOKE "%Y%m%d") # Auto generate dated version
set(PROJECT_VERSION "0.7.0-${MAGIC_SMOKE}") # Generate compile version
### Want a cookie?
# NOTICE: ENABLING THESE DEBUGGING DEFINITIONS WILL HAVE SIGNIFICANT IMPACT AND WILL DELAY PLAYING!
# NOTICE: UART AND USBCDC ARE MUTUALLY EXCLUSIVE!
if(NOT DEFINED $ENV{DISABLE_DEBUGGING}) # MATCHES
set(BUILD_DEBUGGING DEBUG) # Set loglevel from CMake build steps (STATUS,DEBUG,TRACE) override with --log-level
set(USBSID_DEBUGGING 1) # Enable debugging ~ mandatory enable for all other logging types
set(UART_DEBUGGING 1) # Enable debugging over uart pins ~ USBCDC must be 0!
set(USBCDC_DEBUGGING 0) # Enable debugging over cdc port 2 ~ UART must be 0!
set(FILENAME_LOGGING 0) # Enable logging of source filename
set(BOOT_LOGGING 0) # Enable bootlog in usbsid.c
set(DEFAULT_DEBUGGING 1) # Enable debugging in usbsid.c
set(CONFIG_DEBUGGING 1) # Enable debugging in config.c
set(USBIO_DEBUGGING 0) # Enable debugging in usbsid.c
set(GPIOBUS_DEBUGGING 0) # Enable debugging in gpio.c
set(MIDI_DEBUGGING 0) # Enable debugging in midi.c
set(MIDIVOICE_DEBUGGING 0) # Enable debugging in midi.c
set(ASID_DEBUGGING 0) # Enable debugging in acid.c and asid_buffer.c
set(MEMORY_LOGGING 0) # Enable memory map of SID 1 voices printing
set(SIDWRITES_DEBUGGING 0) # Enable logging of SID writes one core 2
set(EMULATOR_DEBUGGING 0) # Enable debugging in emulator
endif()
### Enable / Disable build with embedded emulator for Midi
set(ONBOARD_EMULATOR 0 CACHE STRING "ONBOARD_EMULATOR")
set(ONBOARD_SIDPLAYER 0 CACHE STRING "ONBOARD_SIDPLAYER")
### Enable/ Disable build with PIO Uart on unused pins 26/27
set(USE_PIO_UART 0)
### Information on the use of CDC callback
## This is turned on/off by changing USE_CDC_CALLBACK in globals.h
### Information on the use of Vendor buffer
## This is turned on/off by setting both vendor buffer size
## defines in tusb_config.h and by changing USE_VENDOR_BUFFER in globals.h
# CFG_TUD_VENDOR_TX_BUFSIZE
# CFG_TUD_VENDOR_RX_BUFSIZE
#######################################
#### You no touchy after this line ####
#######################################
### Build notes
# Do not use the below setting, this _will_ break compilation on both
# rp2040 and rp2350
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -std=c++11")
# rp2040 will bug out complaining about assembly calls not being available
# rp2350 will bug out on PICO_USE_SW_SPIN_LOCK not being available
### Build steps log level
set(CMAKE_MESSAGE_LOG_LEVEL ${BUILD_DEBUGGING})
message(DEBUG "LOG_LEVEL is ${CMAKE_MESSAGE_LOG_LEVEL}")
message(DEBUG "Starting compilation of ${PRODUCT_STRING} firmware version ${PROJECT_VERSION}")
if(ONBOARD_EMULATOR EQUAL 1)
message(STATUS "Firmware is built with ONBOARD_EMULATOR")
endif()
if(ONBOARD_SIDPLAYER EQUAL 1)
message(STATUS "Firmware is built with ONBOARD_SIDPLAYER")
endif()
### Optimization and debugging
# remember that enabling debugging and disabling optimizations
# will weird out tune playing and reading from and writing to
# SKPico will stop functioning
# *3 is required for onboard siplayer but could cause desync
# with DMA read_address and chain_to()
set(DEBUG_SYMBOLS 0) # 0 default, 1 debug symbols & debug build enabled
set(DEBUGGING 0) # 0 default, 1~3 equals -g1~3
set(OPTIMIZATIONS 3) # 3 default, 3 ~ -O1 for debugging
set(WARNINGS_ONLY 0) # 0 default, 0 error on warnings
set(TUSB_DEBUG 0) # 0 default, 0~3 non verbose to very verbose
set(ANALYSE_STACKUSAGE 0) # 0 default, 1 enabled, 0 disabled
### Target board pico, pico_w, pico2
if(DEFINED PICO_BOARD)
message(STATUS "PICO_BOARD is defined as ${PICO_BOARD}")
else()
message(WARNING "PICO_BOARD not defined, defaulting to 'pico'")
set(PICO_BOARD pico)
endif()
### Target platform rp2040, rp2350 (rp2350-arm-s)
if(DEFINED PICO_PLATFORM)
message(STATUS "PICO_PLATFORM is defined as ${PICO_PLATFORM}")
else()
if(DEFINED PICO_BOARD)
if(PICO_BOARD STREQUAL "pico2")
set(PICO_PLATFORM rp2350-arm-s)
message(STATUS "PICO_PLATFORM not defined, board is ${PICO_BOARD} setting PICO_PLATFORM to ${PICO_PLATFORM}")
endif()
else()
message(WARNING "PICO_PLATFORM not defined, defaulting to 'rp2040'")
set(PICO_PLATFORM rp2040)
endif()
endif()
### Header validation check
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/src/globals.h)
file(STRINGS ${CMAKE_CURRENT_LIST_DIR}/src/globals.h VALIDATION_FILE)
set(VALIDATION_SUCCESS False)
set(VALIDATION_LINE "#define PROJECT_VERSION")
while(VALIDATION_FILE)
list(POP_FRONT VALIDATION_FILE LINE)
if (LINE MATCHES ${VALIDATION_LINE})
string(REGEX MATCH "^#define PROJECT_VERSION" VALIDATED ${LINE})
if(${VALIDATED} MATCHES ${VALIDATION_LINE})
set(REDUCTION_SUCCESS True)
message(DEBUG "VALIDATED header line '${VALIDATION_LINE}'")
set(USBSID_MANUFACTURER "${PROJECT_MANUFACTURER} (v${PROJECT_VERSION})")
add_compile_definitions(USBSID_MANUFACTURER="${USBSID_MANUFACTURER}")
### CMake shenanigens
set(PJVER ${PROJECT_VERSION})
add_compile_definitions(PROJECT_VERSION="${PJVER}")
break()
else()
message(SEND_ERROR "ERROR header validation line is present but incorrect")
set(REDUCTION_SUCCESS False)
return()
endif()
endif()
endwhile()
if(NOT REDUCTION_SUCCESS)
message(SEND_ERROR "ERROR header validation fallback line not present")
return()
endif()
else()
message(SEND_ERROR "ERROR globals.h missing")
return()
endif()
# ### Compilers to use
if(${PICO_PLATFORM} MATCHES rp2040)
set(PICO_COMPILER pico_arm_cortex_m0plus_gcc)
elseif(${PICO_PLATFORM} MATCHES rp2350)
set(PICO_COMPILER pico_arm_cortex_m33_gcc)
else()
set(PICO_COMPILER pico_arm_gcc) # required for mem_ops on rp2040
endif()
### Cmake compiler standard versions
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
### Target environment path
set(CMAKE_FIND_ROOT_PATH $ENV{PICO_ENV_PATH})
set(TINYUSB_PATH ${PICO_SDK_PATH}/lib/tinyusb)
### Optimizations
set(PICO_DEFAULT_FLOAT_IMPL pico_float_default)
set(PICO_DEFAULT_DOUBLE_IMPL pico_double_default)
### Build with debug symbols
if(DEBUG_SYMBOLS EQUAL 1)
set(CMAKE_BUILD_TYPE Debug) # for debugging
set(PICO_DEOPTIMIZED_DEBUG 1)
if(TUSB_DEBUG EQUAL 0)
set(CFG_TUSB_DEBUG 1)
# add_compile_definitions(CFG_TUSB_DEBUG=1)
else()
set(CFG_TUSB_DEBUG TUSB_DEBUG)
endif()
else()
set(CMAKE_BUILD_TYPE Release)
set(PICO_DEOPTIMIZED_DEBUG 0)
### TinyUSB debug logging
if(TUSB_DEBUG GREATER 0)
message(DEBUG "TinyUSB debugging set to ${TUSB_DEBUG}")
set(CFG_TUSB_DEBUG ${TUSB_DEBUG})
# add_compile_definitions(CFG_TUSB_DEBUG=${TUSB_DEBUG})
else()
set(CFG_TUSB_DEBUG 0)
endif()
endif()
message(STATUS "Firmware build type is ${CMAKE_BUILD_TYPE}")
### Define compile time debugging
if(DEBUGGING EQUAL 0)
set(D_OPT -DNDEBUG)
elseif(DEBUGGING EQUAL 1)
set(D_OPT -g1)
elseif(DEBUGGING EQUAL 2)
set(D_OPT -g2)
elseif(DEBUGGING EQUAL 3)
set(D_OPT -g3)
endif()
### Define compile time optimizations
if(OPTIMIZATIONS EQUAL 0)
set(O_OPT -O0)
elseif(OPTIMIZATIONS EQUAL 1)
set(O_OPT -Og)
elseif(OPTIMIZATIONS EQUAL 2)
set(O_OPT -Ofast)
elseif(OPTIMIZATIONS EQUAL 3)
set(O_OPT -O3)
endif()
if(WARNINGS_ONLY EQUAL 1)
set(W_OPT
-Wall
-Wextra
-Wunused
)
else()
set(W_OPT
-Werror
-Wno-format # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int
-Wno-unused-function # extra check to verify no unused lingering code is present
-Wno-maybe-uninitialized
-Wno-unused
-Wno-misleading-indentation
-Wno-implicit-fallthrough
)
endif()
### Compiler flags and options
set(COMPILE_OPTS PRIVATE
${D_OPT}
${W_OPT}
${O_OPT}
-save-temps
-fverbose-asm
-Wl,--wrap=ceil
-Wl,--wrap=memcpy
-Wl,--wrap=memset
-Wl,--wrap=__aeabi_memcpy
-Wl,--wrap=__aeabi_memset
-Wl,--wrap=__aeabi_memcmp
-Wl,--wrap=__aeabi_memcpy4
-Wl,--wrap=__aeabi_memset4
-Wl,--wrap=__aeabi_memcpy8
-Wl,--wrap=__aeabi_memset8
-Wl,--wrap=printf
-Wl,--wrap=vprintf
-Wl,--wrap=puts
)
if(ANALYSE_STACKUSAGE EQUAL 1)
set(COMPILE_OPTS
${COMPILE_OPTS}
-fstack-usage
-fcallgraph-info
-DANALYSE_STACKUSAGE=1)
endif()
### Target product & output filename
if(${PICO_BOARD} STREQUAL "pico")
set(PROJECT_PRODUCT ${PRODUCT_STRING})
set(PROJECT_FILENAME ${PROJECT_NAME})
elseif(${PICO_BOARD} STREQUAL "pico_w")
set(PROJECT_PRODUCT "${PRODUCT_STRING}_W")
set(PROJECT_FILENAME "${PROJECT_NAME}_w")
elseif(${PICO_BOARD} STREQUAL "pico2")
set(PROJECT_PRODUCT "${PRODUCT_STRING}2")
set(PROJECT_FILENAME "${PROJECT_NAME}2")
elseif(${PICO_BOARD} STREQUAL "pico2_w")
set(PROJECT_PRODUCT "${PRODUCT_STRING}2_W")
set(PROJECT_FILENAME "${PROJECT_NAME}2_w")
endif()
### Executable names
list(APPEND FILENAMES
${PROJECT_FILENAME}-v1.0
${PROJECT_FILENAME}-v1.3
)
list(APPEND PICOTYPES
"LED"
"LED_AUDIOSWITCH"
)
list(APPEND PCBVERSIONS
"1.0"
"1.3"
)
if(${PICO_BOARD} STREQUAL "pico" OR ${PICO_BOARD} STREQUAL "pico2")
list(APPEND FILENAMES
${PROJECT_FILENAME}-v1.0-rgb
${PROJECT_FILENAME}-v1.3-rgb
)
list(APPEND PICOTYPES
"RGB"
"RGB_AUDIOSWITCH"
)
list(APPEND PCBVERSIONS
"1.0"
"1.3"
)
endif()
### Source files to compile
set(SOURCEFILES
${CMAKE_CURRENT_LIST_DIR}/src/usbsid.c
${CMAKE_CURRENT_LIST_DIR}/src/usbsid_doubletap.c
${CMAKE_CURRENT_LIST_DIR}/src/usbsid_constants.c
${CMAKE_CURRENT_LIST_DIR}/src/config.c
${CMAKE_CURRENT_LIST_DIR}/src/config_bus.c
${CMAKE_CURRENT_LIST_DIR}/src/config_socket.c
${CMAKE_CURRENT_LIST_DIR}/src/config_logging.c
${CMAKE_CURRENT_LIST_DIR}/src/gpio.c
${CMAKE_CURRENT_LIST_DIR}/src/pio.c
${CMAKE_CURRENT_LIST_DIR}/src/dma.c
${CMAKE_CURRENT_LIST_DIR}/src/vu.c
${CMAKE_CURRENT_LIST_DIR}/src/bus.c
${CMAKE_CURRENT_LIST_DIR}/src/midi.c
${CMAKE_CURRENT_LIST_DIR}/src/midi_handler.c
${CMAKE_CURRENT_LIST_DIR}/src/asid.c
${CMAKE_CURRENT_LIST_DIR}/src/asid_buffer.c
${CMAKE_CURRENT_LIST_DIR}/src/sysex.c
${CMAKE_CURRENT_LIST_DIR}/src/sid.c
${CMAKE_CURRENT_LIST_DIR}/src/sid_cloneconfig.c
${CMAKE_CURRENT_LIST_DIR}/src/sid_detection.c
${CMAKE_CURRENT_LIST_DIR}/src/sid_tests.c
${CMAKE_CURRENT_LIST_DIR}/src/mcu.c
${CMAKE_CURRENT_LIST_DIR}/src/usb_descriptors.c
)
### Header directories to include
set(TARGET_INCLUDE_DIRS PRIVATE
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/src
${TINYUSB_PATH}/hw
${TINYUSB_PATH}/src
)
### Embedded player stuffs
if(ONBOARD_SIDPLAYER EQUAL 1)
# NOTICE: SIDPLAYER REQUIRES FULL OPTIMIZATIONS!!
# NOTE TO SELF: -O3 is already set in COMPILE_OPTS and applied via target_compile_options()
# NOTE TO SELF: Do NOT use set(CMAKE_CXX_FLAGS ...) here as it strips Pico SDK architecture flags!
## Set sidplayer list directory
if(NOT ${EMUDIR} STREQUAL "")
set(USPLAYER_LIST_DIR ${EMUDIR})
else()
set(USPLAYER_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}/lib/usbsid-player)
endif()
message(DEBUG "USPLAYER_LIST_DIR is set to ${USPLAYER_LIST_DIR}")
### Adjust filenames for user interpretation
foreach(FILENAME ${FILENAMES})
list(APPEND FILENAMES_tmp "${FILENAME}_sp")
endforeach()
set(FILENAMES ${FILENAMES_tmp})
### Build psiddrv header
add_custom_command(
# Use absolute paths
OUTPUT ${USPLAYER_LIST_DIR}/src/psiddrv/psiddrv.h
COMMAND $(MAKE) all
# Remove built .o65 to ensure the linker does not accidentally pick it up
COMMAND ${CMAKE_COMMAND} -E rm -f ${USPLAYER_LIST_DIR}/src/psiddrv/psiddrv.o65
WORKING_DIRECTORY ${USPLAYER_LIST_DIR}/src/psiddrv/
)
add_custom_target(
RSIDDriver ALL
DEPENDS ${USPLAYER_LIST_DIR}/src/psiddrv/psiddrv.h
)
### Add some fancy shmancy necromancy
set(PICO_CXX_ENABLE_EXCEPTIONS 1)
set(COMPILE_OPTS ${COMPILE_OPTS} -DEMBEDDED=1)
add_compile_definitions(ONBOARD_SIDPLAYER=1)
add_compile_definitions(RCUTILS_NO_64_ATOMIC=OFF)
### Where it's at
set(SOURCEFILES
${SOURCEFILES}
${USPLAYER_LIST_DIR}/src/c64/mmu.cpp
${USPLAYER_LIST_DIR}/src/c64/mos6510_cpu.cpp
${USPLAYER_LIST_DIR}/src/c64/mos6526_cia.cpp
${USPLAYER_LIST_DIR}/src/c64/mos6560_6561_vic.cpp
${USPLAYER_LIST_DIR}/src/c64/mos6581_8580_sid.cpp
${USPLAYER_LIST_DIR}/src/c64/mos906114_pla.cpp
${USPLAYER_LIST_DIR}/src/psid/sidfile.cpp
${USPLAYER_LIST_DIR}/src/psiddrv/psid.cpp
${USPLAYER_LIST_DIR}/src/psiddrv/reloc65.c
${USPLAYER_LIST_DIR}/src/util/timer.cpp
${USPLAYER_LIST_DIR}/src/util/wrappers.cpp
${USPLAYER_LIST_DIR}/src/emulation.cpp
${USPLAYER_LIST_DIR}/src/microsid.cpp
${USPLAYER_LIST_DIR}/src/prgrunner.cpp
${USPLAYER_LIST_DIR}/src/usplayer.cpp
${USPLAYER_LIST_DIR}/src/vsidpsid.cpp
)
### What it wants
set(TARGET_INCLUDE_DIRS
${TARGET_INCLUDE_DIRS}
${USPLAYER_LIST_DIR}/src/
${USPLAYER_LIST_DIR}/src/c64
${USPLAYER_LIST_DIR}/src/psid
${USPLAYER_LIST_DIR}/src/psiddrv
${USPLAYER_LIST_DIR}/src/roms
${USPLAYER_LIST_DIR}/src/util
${USPLAYER_LIST_DIR}/src/tunes
)
endif()
### Embedded emulator compilation additions
if(ONBOARD_EMULATOR EQUAL 1)
set(COMPILE_OPTS ${COMPILE_OPTS} -DEMBEDDED=1)
add_compile_definitions(ONBOARD_EMULATOR=1)
set(EMULATOR_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}/lib/emulator)
if(NOT ${EMUDIR} STREQUAL "")
set(EMUDORE_LIST_DIR ${EMUDIR})
else()
set(EMUDORE_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}/lib/emudore-embedded)
endif()
message(DEBUG "EMUDORE_LIST_DIR is set to ${EMUDORE_LIST_DIR}")
### Adjust filenames for user interpretation
foreach(FILENAME ${FILENAMES})
list(APPEND FILENAMES_tmp "${FILENAME}_em")
endforeach()
set(FILENAMES ${FILENAMES_tmp})
set(SOURCEFILES
${SOURCEFILES}
${EMULATOR_LIST_DIR}/emudore_emulator.c
${EMULATOR_LIST_DIR}/interface.cpp
${EMUDORE_LIST_DIR}/src/sidfile.cpp
${EMUDORE_LIST_DIR}/src/cpu.cpp
${EMUDORE_LIST_DIR}/src/memory.cpp
${EMUDORE_LIST_DIR}/src/c64.cpp
${EMUDORE_LIST_DIR}/src/cia1.cpp
${EMUDORE_LIST_DIR}/src/cia2.cpp
${EMUDORE_LIST_DIR}/src/io.cpp
${EMUDORE_LIST_DIR}/src/vic.cpp
${EMUDORE_LIST_DIR}/src/sidadapter.cpp
${EMUDORE_LIST_DIR}/src/pla.cpp
${EMUDORE_LIST_DIR}/src/cart.cpp
${EMUDORE_LIST_DIR}/src/cart/MC68B50.cpp
)
set(TARGET_INCLUDE_DIRS
${TARGET_INCLUDE_DIRS}
${EMULATOR_LIST_DIR}
${EMULATOR_LIST_DIR}/roms
${EMUDORE_LIST_DIR}/src
${EMUDORE_LIST_DIR}/src/cart
)
set(PICO_CXX_ENABLE_EXCEPTIONS 1)
endif()
### PIO Uart compilation additions
if(USE_PIO_UART EQUAL 1)
add_compile_definitions(USE_PIO_UART=1)
set(SOURCEFILES
${SOURCEFILES}
${CMAKE_CURRENT_LIST_DIR}/src/uart.c
)
endif()
### Libraries to link
set(TARGET_LL
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_pio
hardware_pwm
hardware_resets
hardware_structs
hardware_sync
hardware_timer
hardware_uart
# hardware_interp
pico_atomic # memcmp
pico_cxx_options
pico_flash
pico_mem_ops
pico_mem_ops_compiler
pico_malloc
pico_multicore
pico_rand
pico_stdlib
pico_unique_id
pico_usb_reset_interface
pico_async_context_threadsafe_background
tinyusb_device
tinyusb_board
)
### Pio files
set(PIO_BUS ${CMAKE_CURRENT_LIST_DIR}/src/pio/bus_control.pio)
set(PIO_CLOCK ${CMAKE_CURRENT_LIST_DIR}/src/pio/clock.pio)
set(PIO_VU ${CMAKE_CURRENT_LIST_DIR}/src/pio/vu.pio)
set(PIO_RGB ${CMAKE_CURRENT_LIST_DIR}/src/pio/vu_rgb.pio)
set(PIO_COUNTER ${CMAKE_CURRENT_LIST_DIR}/src/pio/cycle_counter.pio)
if(USE_PIO_UART EQUAL 1)
set(PIO_UART ${CMAKE_CURRENT_LIST_DIR}/src/pio/uart_rx.pio)
endif()
### Pico sdk path
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
#include($ENV{PICO_EXTRAS_PATH}/external/pico_extras_import.cmake) # i2s audio
### Project type
project(${PROJECT_NAME} C CXX ASM)
### init sdk
pico_sdk_init()
# Explicitely force pioasm to complete before any firmware targets on clean builds
if(TARGET pioasmBuild)
set(PIOASM_DEPENDENCY pioasmBuild)
endif()
### Include
include_directories(".")
### Double check debugging types
if(UART_DEBUGGING EQUAL 1 AND USBCDC_DEBUGGING EQUAL 1)
message(SEND_ERROR "ERROR cannot have both UART_DEBUGGING and USBCDC_DEBUGGING enabled!")
return()
endif()
### Logging definitions
if(USBSID_DEBUGGING EQUAL 1)
if(UART_DEBUGGING EQUAL 1)
add_compile_definitions(USBSID_UART=1)
endif()
if(USBCDC_DEBUGGING EQUAL 1)
add_compile_definitions(USB_PRINTF=1)
endif()
if(DEFAULT_DEBUGGING EQUAL 1)
add_compile_definitions(USBSID_DEBUG=1)
endif()
if(FILENAME_LOGGING EQUAL 1)
add_compile_definitions(LOG_FILENAME=1)
endif()
if(BOOT_LOGGING EQUAL 1)
add_compile_definitions(USBSID_BOOTLOG=1)
endif()
if(CONFIG_DEBUGGING EQUAL 1)
add_compile_definitions(CONFIG_DEBUG=1)
endif()
if(MEMORY_LOGGING EQUAL 1)
add_compile_definitions(MEM_DEBUG=1)
endif()
if(SIDWRITES_DEBUGGING EQUAL 1)
add_compile_definitions(WRITE_DEBUG=1)
endif()
if(USBIO_DEBUGGING EQUAL 1)
add_compile_definitions(USBIO_DEBUG=1)
endif()
if(MIDI_DEBUGGING EQUAL 1)
add_compile_definitions(MIDI_DEBUG=1)
endif()
if(MIDIVOICE_DEBUGGING EQUAL 1)
add_compile_definitions(MIDIVOICE_DEBUG=1)
endif()
if(ASID_DEBUGGING EQUAL 1)
add_compile_definitions(ASID_DEBUG=1)
endif()
if(GPIOBUS_DEBUGGING EQUAL 1)
add_compile_definitions(USBSIDGPIO_DEBUG=1)
endif()
if(EMULATOR_DEBUGGING EQUAL 1)
add_compile_definitions(EMUDEBUG=1)
endif()
endif()
### It escapes every damn time!
add_compile_definitions(MAGIC_SMOKE=${MAGIC_SMOKE})
### Captain I canna change the options anymore!
message(TRACE "C Compiler root: " ${CMAKE_FIND_ROOT_PATH})
message(TRACE "CXX Compiler root: " ${CMAKE_FIND_ROOT_PATH})
message(TRACE "C Compile time flags:")
message(TRACE "${CMAKE_C_FLAGS}")
message(TRACE "CXX Compile time flags:")
message(TRACE "${CMAKE_CXX_FLAGS}")
message(TRACE "Compile time options:")
message(TRACE "${COMPILE_OPTS}")
message(TRACE "Compile time source files:")
message(TRACE "${SOURCEFILES}")
message(TRACE "Compile time include dirs:")
message(TRACE "${TARGET_INCLUDE_DIRS}")
### Compile targets
foreach(FILENAME PICOTYPE PCBVERSION IN ZIP_LISTS FILENAMES PICOTYPES PCBVERSIONS)
# set filename
set(BUILD ${FILENAME})
set(BUILD_VERSION "")
string(CONCAT BUILD_VERSION ${PROJECT_PRODUCT} " v" ${PCBVERSION})
message(DEBUG "Building ${FILENAME} with PICOTYPE=${PICOTYPE} and MAGIC_SMOKE=${MAGIC_SMOKE}")
message(DEBUG "Set USB manufacturer: ${USBSID_MANUFACTURER}")
message(DEBUG "Set USB product: ${BUILD_VERSION}")
# executable
add_executable(${BUILD} ${SOURCEFILES})
# BUILD TYPES
if(PICOTYPE STREQUAL "RGB")
target_compile_definitions(${BUILD} PRIVATE USBSID USBSID_PRODUCT="${BUILD_VERSION}" USE_RGB=1 PCB_VERSION="${PCBVERSION}")
# add_compile_definitions(USE_RGB=1)
elseif(PICOTYPE STREQUAL "RGB_AUDIOSWITCH")
target_compile_definitions(${BUILD} PRIVATE USBSID USBSID_PRODUCT="${BUILD_VERSION}" USE_RGB=1 HAS_AUDIOSWITCH=1 PCB_VERSION="${PCBVERSION}")
# add_compile_definitions(USE_RGB=1 HAS_AUDIOSWITCH=1)
elseif(PICOTYPE STREQUAL "LED_AUDIOSWITCH")
target_compile_definitions(${BUILD} PRIVATE USBSID USBSID_PRODUCT="${BUILD_VERSION}" HAS_AUDIOSWITCH=1 PCB_VERSION="${PCBVERSION}")
# add_compile_definitions(HAS_AUDIOSWITCH=1)
else()
target_compile_definitions(${BUILD} PRIVATE USBSID USBSID_PRODUCT="${BUILD_VERSION}" PCB_VERSION="${PCBVERSION}")
endif()
# pio addition
pico_generate_pio_header(${BUILD} ${PIO_BUS})
pico_generate_pio_header(${BUILD} ${PIO_CLOCK})
pico_generate_pio_header(${BUILD} ${PIO_VU})
if(USE_PIO_UART EQUAL 1)
pico_generate_pio_header(${BUILD} ${PIO_UART})
endif()
pico_generate_pio_header(${BUILD} ${PIO_COUNTER})
if(PICOTYPE STREQUAL "RGB")
pico_generate_pio_header(${BUILD} ${PIO_RGB})
endif()
# rsiddrv dependency for sidplayer
if(ONBOARD_SIDPLAYER EQUAL 1)
add_dependencies(${BUILD} RSIDDriver)
endif()
# force pioasm to build first on clean builds
if(DEFINED PIOASM_DEPENDENCY)
add_dependencies(${BUILD} ${PIOASM_DEPENDENCY})
endif()
# source files to compile
target_sources(${BUILD} PUBLIC ${SOURCEFILES})
target_compile_options(${BUILD} ${COMPILE_OPTS})
target_link_options(${BUILD} PRIVATE -Xlinker --print-memory-usage)
# memory map linkers
if(${PICO_PLATFORM} MATCHES rp2350)
message(TRACE "Memmap linker, platform ${PICO_PLATFORM} MATCHES rp2350")
target_compile_definitions(${BUILD} PRIVATE USBSID PICO_EMBED_XIP_SETUP=1)
set_target_properties(${BUILD} PROPERTIES PICO_TARGET_LINKER_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/src/usbsidpico-rp2350.ld)
else()
message(TRACE "Memmap linker, platform ${PICO_PLATFORM} EQUALS rp2040")
set_target_properties(${BUILD} PROPERTIES PICO_TARGET_LINKER_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/src/usbsidpico-rp2040.ld)
endif()
# tell the linker what libraries to link
target_link_libraries(${BUILD} ${TARGET_LL})
if (PICO_CYW43_SUPPORTED)
target_link_libraries(${BUILD} pico_cyw43_arch_none)
endif()
# target usbsid types
target_include_directories(${BUILD} ${TARGET_INCLUDE_DIRS})
pico_set_program_name(${BUILD} "USBSID-Pico")
pico_set_program_version(${BUILD} "${PROJECT_VERSION}")
# create map/bin/hex/uf2 file in addition to ELF.
pico_add_extra_outputs(${BUILD})
# enable uart output, disable usb output
pico_enable_stdio_uart(${BUILD} 1) # essentialy the same as LL pico_stdio_uart
pico_enable_stdio_usb(${BUILD} 0)
endforeach()