idf_component_register(
    SRCS
        "src/runtime/platform_core_runtime.c"
        "src/runtime/platform_storage.c"
        "src/runtime/platform_time.c"
        "src/runtime/platform_https_client.c"
        "src/runtime/platform_lan_http_server.c"
        "src/platform_console_driver.c"
        "src/runtime/platform_behavior_runtime.c"
        "src/runtime/platform_multimodal_runtime.c"
        "src/runtime/platform_lcd_runtime.c"
        "src/lcd_face.c"
        "src/platform_stepper_driver.c"
        "src/platform_digital_input_driver.c"
        "src/lcd.c"
        "src/multimodal/audio_pipeline.c"
        "src/multimodal/transport_ws.c"
        "src/wifi_portal_bridge.cpp"
        "src/platform_behavior_stubs.c"
    INCLUDE_DIRS
        "include"
    PRIV_INCLUDE_DIRS
        "internal"
    PRIV_REQUIRES
        78__esp-wifi-connect
        cxx
        driver
        esp_audio_codec
        esp_codec_dev
        esp_driver_gpio
        esp_driver_i2c
        esp_driver_i2s
        esp_driver_spi
        esp_event
        esp_app_format
        esp_http_client
        esp_http_server
        esp_lcd
        esp_netif
        esp_psram
        esp_system
        esp_timer
        esp_wifi
        esp_websocket_client
        json
        littlefs
        log
        lvgl
        espressif__mdns
        mbedtls
        nvs_flash
)

set(platform_lvgl_animation_src_dir "${CMAKE_CURRENT_SOURCE_DIR}/assets/lvgl_animations")
set(platform_lvgl_animation_image_dir "${CMAKE_CURRENT_BINARY_DIR}/lvgl_animations_image")
set(platform_lvgl_animation_stage_stamp "${CMAKE_CURRENT_BINARY_DIR}/lvgl_animations_image.stamp")
file(GLOB_RECURSE platform_lvgl_animation_bin_files CONFIGURE_DEPENDS
    "${platform_lvgl_animation_src_dir}/*.bin"
)

set(platform_lvgl_animation_stage_commands)
foreach(animation_file IN LISTS platform_lvgl_animation_bin_files)
    file(RELATIVE_PATH animation_rel_path "${platform_lvgl_animation_src_dir}" "${animation_file}")
    get_filename_component(animation_rel_dir "${animation_rel_path}" DIRECTORY)
    list(APPEND platform_lvgl_animation_stage_commands
        COMMAND ${CMAKE_COMMAND} -E make_directory "${platform_lvgl_animation_image_dir}/${animation_rel_dir}"
        COMMAND ${CMAKE_COMMAND} -E copy_if_different
            "${animation_file}"
            "${platform_lvgl_animation_image_dir}/${animation_rel_path}"
    )
endforeach()

add_custom_command(
    OUTPUT "${platform_lvgl_animation_stage_stamp}"
    COMMAND ${CMAKE_COMMAND} -E rm -rf "${platform_lvgl_animation_image_dir}"
    COMMAND ${CMAKE_COMMAND} -E make_directory "${platform_lvgl_animation_image_dir}"
    ${platform_lvgl_animation_stage_commands}
    COMMAND ${CMAKE_COMMAND} -E touch "${platform_lvgl_animation_stage_stamp}"
    DEPENDS ${platform_lvgl_animation_bin_files}
)

littlefs_create_partition_image(
    gifpack
    "${platform_lvgl_animation_image_dir}"
    FLASH_IN_PROJECT
    DEPENDS "${platform_lvgl_animation_stage_stamp}"
)
