file(GLOB_RECURSE MAIN_SRCS "${CMAKE_CURRENT_LIST_DIR}/*.c")
# Avoid pulling in sources from the nested driver component, which has its own
# CMakeLists and registration.
list(FILTER MAIN_SRCS EXCLUDE REGEX ".*/drv/.*")
list(FILTER MAIN_SRCS EXCLUDE REGEX ".*/param/.*")
file(GLOB PARAM_SRCS "${CMAKE_CURRENT_LIST_DIR}/param/*.c")
list(APPEND MAIN_SRCS ${PARAM_SRCS})

# Derive a schema hash from the parameter definition so persisted state
# automatically invalidates when the schema changes.
set(STATE_PARAMS_FILE "${CMAKE_CURRENT_LIST_DIR}/../include/state_params.i")
file(SHA1 "${STATE_PARAMS_FILE}" STATE_SCHEMA_SHA1)
string(SUBSTRING "${STATE_SCHEMA_SHA1}" 0 8 STATE_SCHEMA_HASH)
configure_file(
  "${CMAKE_CURRENT_LIST_DIR}/state_version.h.in"
  "${CMAKE_CURRENT_BINARY_DIR}/state_version.h"
  @ONLY)

idf_component_register(
  SRCS ${MAIN_SRCS}
  INCLUDE_DIRS "../include" "${CMAKE_CURRENT_BINARY_DIR}"
  REQUIRES esp_driver_spi spi_flash esp_http_server esp_wifi nvs_flash)
