if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND "$ENV{IDF_PATH}" STREQUAL "")
    cmake_minimum_required(VERSION 3.16)
    project(dali_cpp_gateway LANGUAGES CXX)
endif()

set(DALI_CPP_GATEWAY_SOURCES
    "src/dali_protocol.cpp"
    "src/dali_gateway_cache.cpp"
    "src/dali_gateway_cache_mutation.cpp"
    "src/dali_gateway_reconciliation.cpp"
    "src/dali_application_controller.cpp"
)

if(COMMAND idf_component_register)
    idf_component_register(
        SRCS
            "src/dali_comm.cpp"
            ${DALI_CPP_GATEWAY_SOURCES}
            "src/base.cpp"
            "src/addr.cpp"
            "src/bridge.cpp"
            "src/bridge_model.cpp"
            "src/bridge_provisioning.cpp"
            "src/decode.cpp"
            "src/decode_device_type.cpp"
            "src/decode_dt1.cpp"
            "src/decode_dt4.cpp"
            "src/decode_dt5.cpp"
            "src/decode_dt6.cpp"
            "src/decode_dt8.cpp"
            "src/device.cpp"
            "src/dt1.cpp"
            "src/dt4.cpp"
            "src/dt5.cpp"
            "src/dt6.cpp"
            "src/dt8.cpp"
            "src/sequence.cpp"
            "src/sequence_store.cpp"
            "src/color.cpp"
            "src/gateway_cloud.cpp"
            "src/gateway_provisioning.cpp"
        INCLUDE_DIRS "include"
        REQUIRES mqtt cjson nvs_flash esp_driver_uart
    )

    set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17)
else()
    # Standalone target for IoT adapters that only need the platform-neutral
    # DALI gateway application behavior.
    add_library(dali_cpp_gateway STATIC ${DALI_CPP_GATEWAY_SOURCES})
    target_include_directories(dali_cpp_gateway PUBLIC "${CMAKE_CURRENT_LIST_DIR}/include")
    target_compile_features(dali_cpp_gateway PUBLIC cxx_std_17)

    include(CTest)
    if(BUILD_TESTING)
        add_executable(dali_cpp_gateway_test "tests/dali_gateway_test.cpp")
        target_link_libraries(dali_cpp_gateway_test PRIVATE dali_cpp_gateway)
        add_test(NAME dali_cpp_gateway_test COMMAND dali_cpp_gateway_test)
    endif()
endif()
