74 lines
2.6 KiB
CMake
74 lines
2.6 KiB
CMake
# Parse wifi-credentials from the project root directory at configure-time
|
|
set(PASSWORD_FILE "${CMAKE_CURRENT_SOURCE_DIR}/../wifi-credentials")
|
|
if(EXISTS "${PASSWORD_FILE}")
|
|
file(READ "${PASSWORD_FILE}" PASSWORD_CONTENT)
|
|
string(REGEX MATCH "SSID=([^\r\n]*)" _ "${PASSWORD_CONTENT}")
|
|
set(WIFI_SSID "${CMAKE_MATCH_1}")
|
|
string(REGEX MATCH "PASSWORD=([^\r\n]*)" _ "${PASSWORD_CONTENT}")
|
|
set(WIFI_PASSWORD "${CMAKE_MATCH_1}")
|
|
else()
|
|
set(WIFI_SSID "YOUR_SSID")
|
|
set(WIFI_PASSWORD "YOUR_PASSWORD")
|
|
endif()
|
|
|
|
# Generate wifi_credentials.h inside the build directory so credentials aren't checked into Git
|
|
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/wifi_credentials.h"
|
|
"// Generated by CMake. Do not edit manually.\n\
|
|
#define WIFI_SSID \"${WIFI_SSID}\"\n\
|
|
#define WIFI_PASSWORD \"${WIFI_PASSWORD}\"\n"
|
|
)
|
|
|
|
# Parse device model configuration from the project root directory at configure-time
|
|
set(CONFIG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/../device-config")
|
|
if(EXISTS "${CONFIG_FILE}")
|
|
file(READ "${CONFIG_FILE}" CONFIG_CONTENT)
|
|
string(REGEX MATCH "MODEL=([^\r\n]*)" _ "${CONFIG_CONTENT}")
|
|
set(DEVICE_MODEL "${CMAKE_MATCH_1}")
|
|
else()
|
|
set(DEVICE_MODEL "DEV-1")
|
|
endif()
|
|
|
|
# Generate device_config.h inside the build directory
|
|
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/device_config.h"
|
|
"// Generated by CMake. Do not edit manually.\n\
|
|
#define DEVICE_MODEL \"${DEVICE_MODEL}\"\n"
|
|
)
|
|
|
|
# Register all project source files
|
|
set(SOURCES
|
|
"main.c"
|
|
"wifi_connect.c"
|
|
"socket_client.c"
|
|
"state_manager.c"
|
|
"ota_manager.c"
|
|
"hardeware_driver/bsp_board.c"
|
|
"audio_play_driver/audio_driver.c"
|
|
"tca9555_driver/tca9555_driver.c"
|
|
)
|
|
|
|
# Set include directories, including the generated binary directory
|
|
set(INCLUDE_DIRS
|
|
"."
|
|
"hardeware_driver"
|
|
"audio_play_driver"
|
|
"tca9555_driver"
|
|
"${CMAKE_CURRENT_BINARY_DIR}"
|
|
)
|
|
|
|
# Register the main component with dependencies
|
|
idf_component_register(
|
|
SRCS ${SOURCES}
|
|
INCLUDE_DIRS ${INCLUDE_DIRS}
|
|
PRIV_REQUIRES esp_driver_i2s esp_driver_i2c spi_flash esp_audio_simple_player esp_io_expander_tca95xx_16bit fatfs sdmmc spiffs led_strip esp_wifi nvs_flash esp_event esp_websocket_client esp-tls esp_https_ota app_update esp_driver_ledc esp_adc
|
|
)
|
|
|
|
# Add compile definition based on model to the component library target
|
|
if(DEVICE_MODEL STREQUAL "PROTO-1")
|
|
target_compile_definitions(${COMPONENT_LIB} PRIVATE MODEL_PROTO_1=1)
|
|
else()
|
|
target_compile_definitions(${COMPONENT_LIB} PRIVATE MODEL_DEV_1=1)
|
|
endif()
|
|
|
|
# Package and build the spiffs partition containing startup.mp3
|
|
spiffs_create_partition_image(model spiffs FLASH_IN_PROJECT)
|