# Lisael Box — top-level project CMake for ESP-IDF 5.4/5.5
# Target: ESP32-S3-BOX-3
cmake_minimum_required(VERSION 3.16)

# --- ESP-ADF integration -----------------------------------------------------
# ESP-ADF is NOT a managed component: it is installed separately and exposed via
# the ADF_PATH environment variable (see README "Installer ESP-ADF").
# We add its component tree to EXTRA_COMPONENT_DIRS so that audio_pipeline,
# http_stream, esp_decoder, fatfs_stream, i2s_stream etc. become available.
#
# If ADF_PATH is unset the project still configures, but the audio modules that
# need ADF will fail to link. We surface a clear message instead of a cryptic
# "component not found" error.
if(DEFINED ENV{ADF_PATH})
    set(ADF_COMPONENTS "$ENV{ADF_PATH}/components")
    if(EXISTS "${ADF_COMPONENTS}")
        # On n'ajoute QUE les composants audio nécessaires (pas tout l'arbre ADF) :
        # `audio_board` épingle esp_lcd_ili9341 ^1 et entre en conflit avec le BSP
        # esp-box-3 (qui veut ^2.0.1). On exclut donc audio_board / display_service
        # et on laisse le BSP gérer écran/tactile/SD/codec.
        set(ADF_AUDIO_COMPONENTS
            esp-adf-libs audio_pipeline audio_stream audio_sal esp_dispatcher)
        foreach(_adf_c IN LISTS ADF_AUDIO_COMPONENTS)
            if(EXISTS "${ADF_COMPONENTS}/${_adf_c}")
                list(APPEND EXTRA_COMPONENT_DIRS "${ADF_COMPONENTS}/${_adf_c}")
            endif()
        endforeach()
        message(STATUS "Lisael Box: ESP-ADF audio components from ${ADF_COMPONENTS}")
    else()
        message(WARNING "Lisael Box: ADF_PATH set but ${ADF_COMPONENTS} not found")
    endif()
else()
    message(WARNING
        "Lisael Box: ADF_PATH not set. Audio streaming (webradio / SD playback) "
        "will not link. Run '. $ADF_PATH/export.sh' or export ADF_PATH. "
        "See README.")
endif()

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(lisael_box)
