cmake_minimum_required(VERSION 3.17)
project(zero_copy_example VERSION 1.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

# Buscar paquetes de Qt6 requeridos
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets OpenGL OpenGLWidgets)

# Buscar librerías de FFmpeg mediante PkgConfig
find_package(PkgConfig REQUIRED)
pkg_check_modules(AVCODEC REQUIRED libavcodec)
pkg_check_modules(AVFORMAT REQUIRED libavformat)
pkg_check_modules(AVUTIL REQUIRED libavutil)

# Buscar librerías de CUDA directamente (no requiere nvcc)
find_library(CUDA_LIBRARY NAMES cuda REQUIRED)
find_library(CUDART_LIBRARY NAMES cudart REQUIRED)

# Definir fuentes
set(SOURCES
    main.cpp
    mainwindow.cpp
    glwidget.cpp
    videodecoder.cpp
)

set(HEADERS
    mainwindow.h
    glwidget.h
    videodecoder.h
)

# Definir ejecutable
add_executable(zero_copy_example ${SOURCES} ${HEADERS})

# Enlazar librerías de Qt6, FFmpeg y CUDA
target_link_libraries(zero_copy_example PRIVATE
    Qt6::Core
    Qt6::Gui
    Qt6::Widgets
    Qt6::OpenGL
    Qt6::OpenGLWidgets
    ${AVCODEC_LIBRARIES}
    ${AVFORMAT_LIBRARIES}
    ${AVUTIL_LIBRARIES}
    ${CUDA_LIBRARY}
    ${CUDART_LIBRARY}
)

target_include_directories(zero_copy_example PRIVATE
    ${AVCODEC_INCLUDE_DIRS}
    ${AVFORMAT_INCLUDE_DIRS}
    ${AVUTIL_INCLUDE_DIRS}
)

# Copiar archivos de shaders al directorio de compilación
configure_file(shader.vert shader.vert COPYONLY)
configure_file(shader.frag shader.frag COPYONLY)
