# Lisael Box — main component.
#
# ESP-ADF components (audio_pipeline, esp-adf-libs, audio_stream, esp_decoder,
# audio_board ...) are resolved at configure time from ADF_PATH via
# EXTRA_COMPONENT_DIRS (top-level CMakeLists.txt). They are listed in REQUIRES
# so the linker pulls them in; if ADF_PATH is missing the build fails loudly
# in the audio sources only.
#
# The audio REQUIRES are guarded: when ADF is absent we still let the UI / net
# layers build for inspection. Set LISAEL_WITH_ADF=OFF to compile without audio
# (UI/clock/breathing only) for quick syntax checks on a machine without ADF.

set(srcs
    "app_main.c"
    "net/wifi.c"
    "net/wifi_portal.c"
    "net/file_server.c"
    "net/box_register.c"
    "net/sntp_time.c"
    "net/weather.c"
    "net/udp_log.c"
    "ui/ui.c"
    "ui/fr_date.c"
    "ui/icons.c"
    "modes/home.c"
    "modes/radio.c"
    "modes/calm.c"
    "modes/clock.c"
    "modes/games.c"
    "modes/balloons.c"
    "modes/histoires.c"
    "modes/wifi_setup.c"
    "modes/lire.c"
    "modes/routine.c"
    "audio/audio_player.c"
    "audio/radio_pipeline.c"
    "audio/sd_player.c"
    "audio/aac_player.c"
    "audio/calm_tone.c"
    "audio/podcast_manifest.c"
    "audio/routine_manifest.c"
    "net/podcast.c"
)

# Generated colour icon image descriptors (ui/assets/*.c, Twemoji -> LVGL).
file(GLOB lisael_icon_srcs "${CMAKE_CURRENT_SOURCE_DIR}/ui/assets/*.c")
list(APPEND srcs ${lisael_icon_srcs})

# Generated Fredoka fonts with French accents (ui/fonts/*.c).
file(GLOB lisael_font_srcs "${CMAKE_CURRENT_SOURCE_DIR}/ui/fonts/*.c")
list(APPEND srcs ${lisael_font_srcs})

set(reqs
    nvs_flash
    esp_wifi
    esp_event
    esp_netif
    lwip              # lwip/sockets.h for the UDP log sink
    esp-tls
    esp_http_client
    esp_http_server   # SoftAP captive provisioning portal
    mbedtls          # esp_crt_bundle_attach (CA bundle for HTTPS)
    esp-box-3        # BSP: display, touch, codec, sdcard, sensors
    json             # IDF built-in cJSON component (provides cJSON.h)
    fatfs
    esp_driver_i2c
    esp_driver_tsens  # driver/temperature_sensor.h (internal die temp)
    esp_driver_i2s    # i2s_slot_mode_t in the audio-player clock callback
    chmorgan__esp-audio-player  # MP3 -> PCM player (SD playback, no ESP-ADF)
    espressif__esp_audio_codec  # AAC/M4A simple decoder (podcast self-test)
)

# ESP-ADF audio components. Names follow the ADF master component tree.
# Guarded so a no-ADF inspection build still configures.
if(DEFINED ENV{ADF_PATH})
    list(APPEND reqs
        audio_pipeline
        audio_stream
        esp-adf-libs
        audio_sal
    )
endif()

idf_component_register(
    SRCS ${srcs}
    INCLUDE_DIRS "."
    REQUIRES ${reqs}
)

# GCC 14 (-Werror=array-bounds) émet un faux positif sur l'indexation gardée
# de s_screens[mode] dans ui.c (la garde (unsigned)mode < COUNT est ignorée par
# l'analyse de plage). On désarme l'erreur pour ce composant uniquement.
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-error=array-bounds)

# The generated icon descriptors (ui/assets/*.c) pick their LVGL header via
# LV_LVGL_H_INCLUDE_* macros; without one they fall back to "lvgl/lvgl.h"
# which isn't on the include path. Force the simple "lvgl.h" include.
target_compile_definitions(${COMPONENT_LIB} PRIVATE LV_LVGL_H_INCLUDE_SIMPLE=1)
