set(SOURCES
    "core/system_init.c"
    "core/task_manager.c"
    "provision/wifidevnum_config.c"
    "device/device_model.c"
    "protocol/remote_control.c"
    "protocol/heart_payload.c"
    "drivers/driver_manager.c"
    "drivers/gpiotrol/rc_pwm_control.c"
    "drivers/gpiotrol/devices/device_1201.c"
    "drivers/gpiotrol/devices/device_1101.c"
    "drivers/gpiotrol/devices/device_1102.c"
    "drivers/gpiotrol/betteryread.c"
    "drivers/uart_comm/uart_comm.c"
    "app/app_run.c"
    "app/example_uart_comm_usage.c"
    "main.c"
    "ota_manager.c"
    "ota_binary_stream.c")

if(CONFIG_APP_LINK_BLE)
    list(APPEND SOURCES "link_ble/link_ble.c")
elseif(CONFIG_APP_LINK_UART)
    list(APPEND SOURCES "link_uart/link_uart.c")
else()
    list(APPEND SOURCES "link_wifi/mqttconf_commun.c" "ota.c")
endif()

set(INCLUDE_DIRS
    "."
    "core"
    "device"
    "provision"
    "protocol"
    "app"
    "drivers"
    "drivers/gpiotrol"
    "drivers/gpiotrol/devices"
    "drivers/uart_comm")

if(CONFIG_APP_LINK_BLE)
    list(APPEND INCLUDE_DIRS "link_ble")
elseif(CONFIG_APP_LINK_UART)
    list(APPEND INCLUDE_DIRS "link_uart")
else()
    list(APPEND INCLUDE_DIRS "link_wifi")
endif()

set(MAIN_REQUIRES
    driver
    app_update
    nvs_flash
    esp_http_server
    spiffs
    esp-tls
    esp_netif
    esp_event
    esp_wifi
    esp_adc
    json)

set(MAIN_PRIV_REQUIRES)

# 避免配置切换/缓存导致 main 编译 link_ble.c 时丢失 bt 头文件路径，
# 这里始终将 bt 放入 main 的私有依赖。
list(APPEND MAIN_PRIV_REQUIRES bt)

if(CONFIG_APP_LINK_WIFI)
    list(APPEND MAIN_REQUIRES mqtt esp_https_ota esp_http_client)
endif()

idf_component_register(SRCS ${SOURCES}
                    INCLUDE_DIRS ${INCLUDE_DIRS}
                    REQUIRES ${MAIN_REQUIRES}
                    PRIV_REQUIRES ${MAIN_PRIV_REQUIRES})

spiffs_create_partition_image(storage ../www FLASH_IN_PROJECT)
