cmake_minimum_required(VERSION 3.14)
project(lluav_sdk VERSION 1.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Dependencies
find_package(Threads REQUIRED)
find_package(PkgConfig QUIET)

# Try to find websocketpp
find_path(WEBSOCKETPP_INCLUDE websocketpp/client.hpp
    PATHS /usr/include /usr/local/include
)
if(NOT WEBSOCKETPP_INCLUDE)
    message(FATAL_ERROR "websocketpp not found. Install via: sudo apt install libwebsocketpp-dev")
endif()

# Try to find nlohmann/json
find_path(NLOHMANN_JSON_INCLUDE nlohmann/json.hpp
    PATHS /usr/include /usr/local/include
)
if(NOT NLOHMANN_JSON_INCLUDE)
    message(FATAL_ERROR "nlohmann/json not found. Install via: sudo apt install nlohmann-json3-dev")
endif()

# Library
add_library(lluav_sdk STATIC
    src/client.cpp
)

target_include_directories(lluav_sdk PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
    $<INSTALL_INTERFACE:include>
    ${WEBSOCKETPP_INCLUDE}
    ${NLOHMANN_JSON_INCLUDE}
)

target_link_libraries(lluav_sdk PUBLIC
    Threads::Threads
)

# Examples
option(LLUAV_SDK_BUILD_EXAMPLES "Build examples" ON)
if(LLUAV_SDK_BUILD_EXAMPLES)
    add_executable(basic_usage examples/basic_usage.cpp)
    target_link_libraries(basic_usage PRIVATE lluav_sdk)
endif()

# Demos
option(LLUAV_SDK_BUILD_DEMOS "Build demos" ON)
if(LLUAV_SDK_BUILD_DEMOS)
    add_executable(demo_state_monitor demos/demo_state_monitor.cpp)
    target_link_libraries(demo_state_monitor PRIVATE lluav_sdk)

    add_executable(demo_flight_mission demos/demo_flight_mission.cpp)
    target_link_libraries(demo_flight_mission PRIVATE lluav_sdk)

    add_executable(demo_camera_map demos/demo_camera_map.cpp)
    target_link_libraries(demo_camera_map PRIVATE lluav_sdk)
endif()

# Install
install(TARGETS lluav_sdk
    ARCHIVE DESTINATION lib
    LIBRARY DESTINATION lib
)
install(DIRECTORY include/ DESTINATION include)
