cmake_minimum_required(VERSION 3.16)
project(StreamHubQtClient CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# The reused, framework-free Protocol.h / Model.h structs have members named
# "signals" (e.g. ZoomResponse::signals). Qt's default "signals"/"slots"/"emit"
# keyword macros would clobber them, so disable the macros and use the
# Q_SIGNALS / Q_SLOTS / Q_EMIT spellings in our own Qt classes instead.
add_compile_definitions(QT_NO_KEYWORDS)

# ── Qt5/Qt6 autodetect (prefer Qt6, fall back to Qt5) ─────────────────────────
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets WebSockets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets WebSockets)
message(STATUS "StreamHubQtClient: building against Qt${QT_VERSION_MAJOR} "
               "(${QT_VERSION})")

# ── Reuse the wire layer from the ImGui client (single source of truth) ───────
set(REF_CLIENT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../streamhub)

set(SOURCES
    main.cpp
    Theme.cpp
    Hub.cpp
    WsClient.cpp
    PlotWidget.cpp
    PlotGrid.cpp
    SourceSidebar.cpp
    TriggerBar.cpp
    StatsDialog.cpp
    HistoryBar.cpp
    MainWindow.cpp
    # Reused, framework-free protocol implementation:
    ${REF_CLIENT_DIR}/Protocol.cpp
)

set(HEADERS
    Model.h
    Theme.h
    Hub.h
    WsClient.h
    PlotWidget.h
    PlotGrid.h
    SourceSidebar.h
    TriggerBar.h
    StatsDialog.h
    HistoryBar.h
    MainWindow.h
)

add_executable(StreamHubQtClient ${SOURCES} ${HEADERS})

target_include_directories(StreamHubQtClient PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${REF_CLIENT_DIR}          # Protocol.h, SignalBuffer.h
)

target_link_libraries(StreamHubQtClient PRIVATE
    Qt${QT_VERSION_MAJOR}::Widgets
    Qt${QT_VERSION_MAJOR}::WebSockets
)

target_compile_options(StreamHubQtClient PRIVATE -Wall -Wextra -Wno-unused-parameter)

install(TARGETS StreamHubQtClient DESTINATION bin)
