cmake_minimum_required(VERSION 3.16)
project(indi_esp32_flatpanel CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Find required packages
find_package(INDI    REQUIRED)
find_package(CURL    REQUIRED)

# nlohmann/json – header-only, installed via `apt install nlohmann-json3-dev`
# or fetched automatically below if not found
find_package(nlohmann_json QUIET)
if(NOT nlohmann_json_FOUND)
    include(FetchContent)
    FetchContent_Declare(json
        URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz)
    FetchContent_MakeAvailable(json)
endif()

include_directories(${INDI_INCLUDE_DIR})

add_executable(indi_esp32_flatpanel
    indi_esp32_flatpanel.cpp
)

target_link_libraries(indi_esp32_flatpanel
    ${INDI_LIBRARIES}
    CURL::libcurl
    nlohmann_json::nlohmann_json
    pthread
)

# Install binary and XML descriptor
install(TARGETS indi_esp32_flatpanel
    RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)

install(FILES indi_esp32_flatpanel.xml
    DESTINATION ${INDI_DATA_DIR})
