# Generated Cmake Pico project file

cmake_minimum_required(VERSION 3.13)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Initialise pico_sdk from installed location
# (note this can come from environment, CMake cache etc)

# == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work ==
if(WIN32)
    set(USERHOME $ENV{USERPROFILE})
else()
    set(USERHOME $ENV{HOME})
endif()
set(sdkVersion 2.2.0)
set(toolchainVersion 14_2_Rel1)
set(picotoolVersion 2.2.0-a4)
set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake)
if (EXISTS ${picoVscode})
    include(${picoVscode})
endif()
# ====================================================================================
# Default to Feather RP2350, but allow override via -DPICO_BOARD=<board>
if(NOT PICO_BOARD)
    set(PICO_BOARD adafruit_feather_rp2350 CACHE STRING "Board type")
endif()
message(STATUS "Building for board: ${PICO_BOARD}")

# Pull in Raspberry Pi Pico SDK (must be before project)
include(pico_sdk_import.cmake)

project(basic1 C CXX ASM)

# Initialise the Raspberry Pi Pico SDK
pico_sdk_init()

# Add executable. Default name is the project name, version 0.1

# Collect Lua source files
file(GLOB LUA_SOURCES 
    "${CMAKE_CURRENT_LIST_DIR}/lib/lua/*.c"
)

add_executable(basic1 
    basic1.cpp 
    lib/input_manager.cpp
    lib/game_launcher.cpp
    games/tic_tac_toe.cpp
    games/demo_game.cpp
    games/monopoly/monopoly_game.cpp
    games/monopoly/player.c
    games/lua_game.cpp
    games/lua_bindings.cpp
    games/lua_game_loader.cpp
    lib/st7796/st7796.c 
    lib/st7789/st7789.c 
    lib/ft6336u/ft6336u.c 
    lib/sd_card/sd_card.c 
    display/low_level_render.cpp 
    display/low_level_gui.cpp
    display/low_level_display_factory.cpp
    display/low_level_display_st7796.cpp
    display/low_level_display_st7789.cpp
    display/low_level_display_epaper.cpp
    display/low_level_touch_factory.cpp
    display/low_level_touch_ft6336u.cpp
    diskio_sdcard.c
    fatfs_time.c
    lib/fatfs/source/ff.c
    lib/fatfs/source/ffsystem.c
    lib/fatfs/source/ffunicode.c
    lib/Pico_ePaper_Code/c/lib/Config/DEV_Config.c
    lib/Pico_ePaper_Code/c/lib/e-Paper/EPD_4in2_V2.c
    ${LUA_SOURCES}
)

pico_set_program_name(basic1 "basic1")
pico_set_program_version(basic1 "0.1")

# Add compile definitions early (before headers are parsed)
target_compile_definitions(basic1 PRIVATE
    PICO_BOARD_ADAFRUIT_FEATHER_RP2350=1
    LUA_32BITS  # Use 32-bit integers for Lua on embedded
)

# Modify the below lines to enable/disable output over UART/USB
pico_enable_stdio_uart(basic1 0)
pico_enable_stdio_usb(basic1 1)

# Add the standard library to the build
target_link_libraries(basic1
        pico_stdlib
        hardware_dma
        hardware_spi
        hardware_pwm
)

# Add the standard include files to the build
target_include_directories(basic1 PRIVATE
    ${CMAKE_CURRENT_LIST_DIR}
    ${CMAKE_CURRENT_LIST_DIR}/games
    ${CMAKE_CURRENT_LIST_DIR}/games/monopoly
    ${CMAKE_CURRENT_LIST_DIR}/lib
    ${CMAKE_CURRENT_LIST_DIR}/lib/lua
    ${CMAKE_CURRENT_LIST_DIR}/lib/fatfs/source
    ${CMAKE_CURRENT_LIST_DIR}/lib/st7796
    ${CMAKE_CURRENT_LIST_DIR}/lib/st7789
    ${CMAKE_CURRENT_LIST_DIR}/lib/ft6336u
    ${CMAKE_CURRENT_LIST_DIR}/lib/sd_card
    ${CMAKE_CURRENT_LIST_DIR}/display
    ${CMAKE_CURRENT_LIST_DIR}/lib/Pico_ePaper_Code/c/lib/Config
    ${CMAKE_CURRENT_LIST_DIR}/lib/Pico_ePaper_Code/c/lib/e-Paper
)

# Add any user requested libraries
target_link_libraries(basic1 
        hardware_spi
        hardware_i2c
        hardware_pwm
        pico_multicore
        m
)

pico_add_extra_outputs(basic1)

# RP2350-specific: Set the boot stage2 and ensure proper image definition
# This is critical for reliable cold boot on RP2350
pico_set_binary_type(basic1 default)
