# 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.5)

message(STATUS "=== joyinside_wss Build Configuration ===")
message(STATUS "ARMINO_PATH = $ENV{ARMINO_PATH}")

# --- Auto-apply SDK patches from components/ ---
# Files in components/ override their SDK counterparts at configure time.
# This enables project-specific SDK fixes without permanently modifying the SDK tree.
set(PATCH_DIR ${CMAKE_CURRENT_LIST_DIR}/components)
set(PATCH_TARGETS
    "aud_intf.c|$ENV{ARMINO_PATH}/../components/multimedia/app/aud_intf.c"
    "aud_intf.h|$ENV{ARMINO_PATH}/../components/multimedia/include/aud_intf.h"
    "aud_tras_drv.c|$ENV{ARMINO_PATH}/../components/multimedia/aud/aud_tras_drv.c"
    "webclient.c|$ENV{ARMINO_PATH}/components/webclient/webclient.c"
    "bk_ssl.c|$ENV{ARMINO_PATH}/components/bk_websocket/bk_ssl.c"
    "bk_websocket_client.c|$ENV{ARMINO_PATH}/components/bk_websocket/bk_websocket_client.c"
)
foreach(entry ${PATCH_TARGETS})
    string(REPLACE "|" ";" parts "${entry}")
    list(GET parts 0 src_name)
    list(GET parts 1 dst_path)
    set(src_path "${PATCH_DIR}/${src_name}")
    if(EXISTS "${src_path}")
        message(STATUS "[patch] ${src_name} -> ${dst_path}")
        configure_file("${src_path}" "${dst_path}" COPYONLY)
    endif()
endforeach()

# Component directories for joyinside_wss project
# Voice-only WebSocket client — no video, no local ASR, no Agora
set(EXTRA_COMPONENTS_DIRS
    # Core components from bk_avdk (required)
    $ENV{ARMINO_PATH}/../components
    $ENV{ARMINO_PATH}/../components/include/avdk

    # Factory config
    $ENV{ARMINO_PATH}/../../components/bk_factory_config

    # Audio components (required for voice pipeline)
    $ENV{ARMINO_PATH}/../components/audio_algorithms
    $ENV{ARMINO_PATH}/../components/multimedia
    $ENV{ARMINO_PATH}/../components/codec/
    $ENV{ARMINO_PATH}/../components/avdk_utils

    # Codec and utilities
    $ENV{ARMINO_PATH}/../properties/modules
    $ENV{ARMINO_PATH}/../properties/modules/audio_codec

    # Base64 from bk_idk
    $ENV{ARMINO_PATH}/components/base64

    # Only keep the common components that this project still uses directly
    $ENV{ARMINO_PATH}/../../projects/common_components/bk_led_blink
    $ENV{ARMINO_PATH}/../../projects/common_components/bk_motor
    )

include($ENV{ARMINO_PATH}/tools/build_tools/cmake/project.cmake)
project(beken_wss)
