# opencv 4.10.0 — visión por computadora. Campaña KDE (ADR 0011): spectacle (la herramienta de CAPTURA DE
# PANTALLA) lo exige — `find_package(OpenCV 4.7 REQUIRED core imgproc)` (lo usa en src/QtCV.h para el
# detector de rectángulos/ventanas de la captura).
#
# OpenCV es enorme (~95MB de fuente, decenas de módulos). Se recorta a los DOS módulos que spectacle pide
# (core + imgproc) con BUILD_LIST, y se apaga todo lo demás: sin apps/tests/perf-tests/docs/examples, sin
# Python/Java, sin protobuf/DNN, sin GUI (highgui/gtk/qt), sin video/ffmpeg/gstreamer, sin IPP/TBB/CUDA.
# BUILD_LIST=core,imgproc hace que CMake ni configure los demás módulos.
#
# WITH_* de codecs OFF: OpenCV traería sus terceros (libjpeg/png/tiff/webp/openjpeg propios). imgproc no
# los necesita (los codecs viven en imgcodecs, que no construimos).
name    = "opencv"
version = "4.10.0"

[source]
tarball = "https://github.com/opencv/opencv/archive/refs/tags/4.10.0.tar.gz"
sha256  = "b2171af5be6b26f7a06b1229948bbb2bdaa74fcf5cd097e0af6378fce50a6eb9"

[build]
compiler = "zig-cc"
target   = "x86_64-linux-musl"
link     = "dynamic"
flags    = []

[build.phases]
configure = '''
# Wrapper zig PASS-THROUGH con "$@": el wrapper clásico de esta cola arma la lista en $a SIN comillas y
# SPLITEA los args con espacios. OpenCV pasa -DOPENCV_ALLOCATOR_STATS_COUNTER_TYPE="long long" ⇒ el
# clásico lo parte y zig ve "long" como fichero ("error: long: unrecognized file extension"). Acá no hace
# falta el filtro de -Wl,--fatal-warnings (OpenCV no es ECM/KDE), así que se pasa todo tal cual.
ZW="$PWD/.zwrap"; mkdir -p "$ZW"
cat > "$ZW/cc"  <<'W'
#!/bin/sh
exec /opt/zig/zig cc -mcpu=baseline "$@"
W
cat > "$ZW/cxx" <<'W'
#!/bin/sh
exec /opt/zig/zig c++ -mcpu=baseline "$@"
W
chmod +x "$ZW/cc" "$ZW/cxx"
cmake -B build -G Ninja -Wno-dev \
  -DCMAKE_C_COMPILER="$ZW/cc" -DCMAKE_CXX_COMPILER="$ZW/cxx" \
  -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_PREFIX_PATH=/usr \
  -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF -DBUILD_SHARED_LIBS=ON \
  -DBUILD_LIST=core,imgproc \
  -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_DOCS=OFF \
  -DBUILD_opencv_apps=OFF -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=OFF \
  -DBUILD_JAVA=OFF -DBUILD_PROTOBUF=OFF -DWITH_PROTOBUF=OFF \
  -DWITH_GTK=OFF -DWITH_QT=OFF -DWITH_OPENGL=OFF -DWITH_VTK=OFF \
  -DWITH_FFMPEG=OFF -DWITH_GSTREAMER=OFF -DWITH_V4L=OFF -DWITH_1394=OFF \
  -DWITH_JPEG=OFF -DWITH_PNG=OFF -DWITH_TIFF=OFF -DWITH_WEBP=OFF -DWITH_OPENJPEG=OFF -DWITH_JASPER=OFF \
  -DWITH_OPENEXR=OFF -DWITH_IPP=OFF -DWITH_TBB=OFF -DWITH_CUDA=OFF -DWITH_OPENCL=OFF \
  -DWITH_ITT=OFF -DWITH_ADE=OFF -DWITH_EIGEN=OFF -DWITH_LAPACK=OFF -DWITH_QUIRC=OFF \
  -DOPENCV_GENERATE_PKGCONFIG=ON
'''
compile = "cmake --build build"
install = "DESTDIR=/out cmake --install build"

[deps]
build = ["cmake", "samurai", "python3", "pkgconf", "zlib-shared"]
