# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# "Trim" the build. Include the minimal set of components, main, and anything it depends on.
idf_build_set_property(MINIMAL_BUILD ON)
project(TQ_Cat_Code)

idf_build_get_property(TQ_PROJECT_VERSION PROJECT_VER)
set(TQ_VERSIONED_FIRMWARE
    "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}-${TQ_PROJECT_VERSION}.bin")

add_custom_target(versioned_firmware ALL
    COMMAND ${CMAKE_COMMAND} -E copy_if_different
        "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.bin"
        "${TQ_VERSIONED_FIRMWARE}"
    DEPENDS app
    BYPRODUCTS "${TQ_VERSIONED_FIRMWARE}"
    COMMENT "Creating versioned firmware ${CMAKE_PROJECT_NAME}-${TQ_PROJECT_VERSION}.bin"
    VERBATIM
)

# 依赖应用和模型产物，确保每次构建输出的是本次镜像的分区及空间数据。
add_custom_target(flash_usage_report ALL
    COMMAND ${PYTHON} "${CMAKE_SOURCE_DIR}/tools/report_flash_usage.py"
        --partition-table "${CMAKE_BINARY_DIR}/partition_table/partition-table.bin"
        --app "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.bin"
        --asset-pack "${CMAKE_BINARY_DIR}/esp-idf/platform/platform_assets.pack"
        --model "${CMAKE_BINARY_DIR}/srmodels/srmodels.bin"
        --flash-size "${CONFIG_ESPTOOLPY_FLASHSIZE}"
    DEPENDS versioned_firmware srmodels_bin
    COMMENT "Reporting Flash partition and embedded asset usage"
    VERBATIM
)
