set(PROJECT aw410k_rgb)
cmake_minimum_required(VERSION 3.13)
set(PICO_SDK_PATH /home/kenji/programming/pico/c/pico-sdk)
set(PICO_PIO_USB_PATH /home/kenji/programming/pico/c/Pico-PIO-USB)
if (NOT DEFINED PICO_BOARD)
	set(PICO_BOARD pico)
endif()
set(TUSB_NETWORKING_PATH ${PICO_SDK_PATH}/lib/tinyusb/lib/networking)
include (${PICO_SDK_PATH}/external/pico_sdk_import.cmake)
project(${PROJECT} C CXX ASM)

set(MAKE_FS_DATA_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/external/makefsdata)
set(HTML_DIR ${CMAKE_CURRENT_LIST_DIR}/html)

if (NOT EXISTS ${MAKE_FS_DATA_SCRIPT})
	file(DOWNLOAD
		https://raw.githubusercontent.com/lwip-tcpip/lwip/e799c266facc3c70190676eccad49d6c2db2caac/src/apps/http/makefsdata/makefsdata
		${MAKE_FS_DATA_SCRIPT}
	)
endif()
message("Running makefsdata script")
execute_process(COMMAND
	perl ${MAKE_FS_DATA_SCRIPT}
	WORKING_DIRECTORY ${HTML_DIR}
	ECHO_OUTPUT_VARIABLE
	ECHO_ERROR_VARIABLE
)
file(RENAME ${HTML_DIR}/fsdata.c ${CMAKE_CURRENT_LIST_DIR}/my_fsdata.c)

pico_sdk_init()

add_subdirectory(${PICO_PIO_USB_PATH} pico_pio_usb)

add_executable(${PROJECT})
target_sources(${PROJECT} PRIVATE
	aw410k.c
	main.c
	usb_device.c
	usb_host.c
	usb_server.c
	websocket.c
	${TUSB_NETWORKING_PATH}/dhserver.c
	${TUSB_NETWORKING_PATH}/dnserver.c
)

 # print memory usage, enable all warnings
target_link_options(${PROJECT} PRIVATE -Xlinker --print-memory-usage)
target_compile_options(${PROJECT} PRIVATE ) #-Wall -Wextra

# use tinyusb implementation
target_compile_definitions(${PROJECT} PRIVATE PIO_USB_USE_TINYUSB)

# needed so tinyusb can find tusb_config.h
target_include_directories(${PROJECT} PRIVATE
	${CMAKE_CURRENT_LIST_DIR}
	${TUSB_NETWORKING_PATH}
)

target_link_libraries(${PROJECT} PRIVATE
	pico_lwip
	pico_lwip_arch
	pico_lwip_http
	pico_mbedtls
	pico_stdlib
	pico_pio_usb
	tinyusb_board
	tinyusb_device
	tinyusb_host
	tinyusb_pico_pio_usb
	hardware_adc
)

set_target_properties(${PROJECT} PROPERTIES OUTPUT_NAME "${PROJECT}-            ${PICO_BOARD}")

pico_add_extra_outputs(${PROJECT})

