cmake_minimum_required(VERSION 3.10.0)

project(Hyperion_Grabber_X11_QT VERSION 0.1 LANGUAGES C CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_BUILD_TYPE Release)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt6 COMPONENTS Core Gui WaylandClient Multimedia Widgets MultimediaWidgets REQUIRED)

# Add the Wayland POC executable
add_executable(wayland_poc "wayland_poc.cpp")

find_program(WAYLAND_SCANNER_EXECUTABLE NAMES wayland-scanner)

set(WAYLAND_PROTOCOLS_DIR "${CMAKE_CURRENT_BINARY_DIR}/wayland_protocols")
file(MAKE_DIRECTORY ${WAYLAND_PROTOCOLS_DIR})

add_custom_command(
    OUTPUT ${WAYLAND_PROTOCOLS_DIR}/qwayland-zkde-screencast-unstable-v1.h
    COMMAND ${WAYLAND_SCANNER_EXECUTABLE} client-header "${CMAKE_CURRENT_SOURCE_DIR}/cloned_repos/plasma-wayland-protocols/src/protocols/zkde-screencast-unstable-v1.xml" ${WAYLAND_PROTOCOLS_DIR}/qwayland-zkde-screencast-unstable-v1.h
    DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/cloned_repos/plasma-wayland-protocols/src/protocols/zkde-screencast-unstable-v1.xml"
    COMMENT "Generating Wayland client header for zkde-screencast-unstable-v1"
)

add_custom_command(
    OUTPUT ${WAYLAND_PROTOCOLS_DIR}/zkde-screencast-unstable-v1-client-protocol.h
    COMMAND ${WAYLAND_SCANNER_EXECUTABLE} code "${CMAKE_CURRENT_SOURCE_DIR}/cloned_repos/plasma-wayland-protocols/src/protocols/zkde-screencast-unstable-v1.xml" ${WAYLAND_PROTOCOLS_DIR}/zkde-screencast-unstable-v1-client-protocol.h
    DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/cloned_repos/plasma-wayland-protocols/src/protocols/zkde-screencast-unstable-v1.xml"
    COMMENT "Generating Wayland client protocol code for zkde-screencast-unstable-v1"
)

add_custom_target(generate_wayland_protocols ALL
    DEPENDS ${WAYLAND_PROTOCOLS_DIR}/qwayland-zkde-screencast-unstable-v1.h
            ${WAYLAND_PROTOCOLS_DIR}/zkde-screencast-unstable-v1-client-protocol.h
)

find_package(PkgConfig REQUIRED)
pkg_check_modules(PIPEWIRE REQUIRED libpipewire-0.3)



target_include_directories(wayland_poc PRIVATE ${WAYLAND_PROTOCOLS_DIR} ${PIPEWIRE_INCLUDE_DIRS})
add_dependencies(wayland_poc generate_wayland_protocols)

target_link_libraries(wayland_poc
    Qt6::Core
    Qt6::Gui
    Qt6::WaylandClient
    Qt6::Multimedia
    Qt6::Widgets
    Qt6::MultimediaWidgets
    ${PIPEWIRE_LIBRARIES}
)
