cmake_minimum_required(VERSION 3.16)
project(UARTScope VERSION 1.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

find_package(Qt6 REQUIRED COMPONENTS
    Core
    Gui
    Widgets
    SerialPort
)

set(SOURCES
    src/main.cpp
    src/mainwindow.cpp
    src/serialworker.cpp
    src/rawview.cpp
    src/tableview.cpp
    src/tagwidget.cpp
    src/tagpanel.cpp
    src/connectdialog.cpp
    src/v4l2worker.cpp
    src/videowidget.cpp
)

set(HEADERS
    include/mainwindow.h
    include/serialworker.h
    include/rawview.h
    include/tableview.h
    include/tagwidget.h
    include/tagpanel.h
    include/connectdialog.h
    include/v4l2worker.h
    include/videowidget.h
)

qt6_add_resources(RESOURCES resources.qrc)
add_executable(uartscope ${SOURCES} ${HEADERS} ${RESOURCES})

target_include_directories(uartscope PRIVATE include)

target_link_libraries(uartscope PRIVATE
    Qt6::Core
    Qt6::Gui
    Qt6::Widgets
    Qt6::SerialPort
)

# V4L2 uses Linux kernel headers directly (linux/videodev2.h)
# These are part of linux-api-headers / linux-libc-dev on all major distros.
# No additional library linkage needed.

# Installation
install(TARGETS uartscope DESTINATION bin)

# Optional: create a .desktop file for Linux app launchers
configure_file(
    ${CMAKE_SOURCE_DIR}/uartscope.desktop.in
    ${CMAKE_BINARY_DIR}/uartscope.desktop
    @ONLY
)
install(FILES ${CMAKE_BINARY_DIR}/uartscope.desktop DESTINATION share/applications)
install(FILES ${CMAKE_SOURCE_DIR}/UartscopeLogo.png
        DESTINATION share/icons/hicolor/512x512/apps
        RENAME uartscope.png)
