{% set version = "4.5.5" %}
{% set build_num = "2" %}
package:
  name: opencv-suite
  version: {{ version }}

source:
  {% if USE_GIT|default(False) %}
  - git_url: https://github.com/opencv/opencv
    git_tag: {{ version }}
    git_depth: 10
{% else %}
  - url: https://github.com/opencv/opencv/archive/{{ version }}.zip
    fn: opencv-{{ version }}.zip
    sha256: fb16b734db3a28e5119d513bd7c61ef417edf3756165dc6259519bb9d23d04e2
{% endif %}
  - url: https://github.com/opencv/opencv_contrib/archive/{{ version }}.tar.gz
    fn: opencv_contrib-{{ version }}.tar.gz
    sha256: a97c2eaecf7a23c6dbd119a609c6d7fae903e5f9ff5f1fe678933e01c67a6c11
    folder: opencv_contrib-{{ version }}
  - patches:  # [win]
    # See https://github.com/opencv/opencv/issues/21393
    - gstreamer-audio-windows.patch  # [win]

build:
  number: {{ build_num }}
  # Package not supported on win32 and s390x
  skip: true  # [win32 or s390x or (aarch64 and py>39)]
  ignore_run_exports:
    - openblas-devel  # [x86_64 and not win]
    - _openmp_mutex  # [linux]
    - python
    - libwebp-base # [win]
    - gst-plugins-base # [win]
    - qt         # [win]
    - gstreamer  # [win]
    - glib       # [win]
    - libtiff    # [win]
    - hdf5       # [win]
    - libpng     # [win]
    - zlib       # [win]
  missing_dso_whitelist:     # [osx]
    - "*"   # [osx]

requirements:
  build:
    - {{ compiler('c') }}
    - {{ compiler('cxx') }}
    - patch  # [not win]
    - m2-patch  # [win]
    - ninja
    - pkg-config
    - {{ cdt('mesa-libGL-devel') }}  # [linux]
    - {{ cdt('mesa-libEGL-devel') }}  # [linux and not ppc64le]
  host:
    - cmake
    - jasper                # [win]
    - eigen
    - ffmpeg                # [linux64 or win]
    - freetype              # [not win]
    - glib                  # [not ppc64le]
    - gst-plugins-base      # [not (win or ppc64le)]
    - gstreamer             # [not (win or ppc64le)]
    - gst-plugins-base ==1.18.5      # [win]
    - gstreamer ==1.18.5             # [win]
    - harfbuzz              # [not win]
    - hdf5
    - jpeg                  # [not win]
    - openjpeg              # [not (win or arm64)]
    - openblas-devel        # [x86_64 and not win]
    - libpng
    - libprotobuf           # [linux64 or win]
    - libtiff
    - libwebp-base          # [win or linux64]
    - numpy {{ numpy }}
    - python
    - qt ==5.9.7            # [(x86_64 or win) and not ppc64le]
    - qt ==5.15.2           # [arm64 or aarch64]
    - zlib
  run:
    - _openmp_mutex         # [linux]
    - eigen
    - ffmpeg                # [linux64]
    - freetype              # [not win]
    - jasper                # [win]
    - glib                  # [not ppc64le]
    - gst-plugins-base      # [not (win or ppc64le)]
    - gstreamer             # [not (win or ppc64le)]
    - gst-plugins-base ==1.18.5      # [win]
    - gstreamer ==1.18.5             # [win]
    - harfbuzz              # [not win]
    - hdf5
    - jpeg                  # [not win]
    - openjpeg              # [not (win or arm64)]
    - libopenblas           # [x86_64 and not win]
    - libpng
    - libtiff
    - libwebp-base          # [win or linux64]
    - numpy {{ numpy }}
    - python
    - qt ==5.9.7            # [(x86_64 or win) and not ppc64le]
    - qt ==5.15.2           # [arm64 or aarch64]
    - zlib


outputs:
  - name: opencv
    script: install.sh                           # [not win]
    script: install.bat                          # [win]
    build:
      ignore_run_exports:
        - openblas-devel # [x86_64 and not win]
        - libwebp-base # [win]
        - gst-plugins-base # [win]
        - qt         # [win]
        - gstreamer  # [win]
        - glib       # [win]
        - libtiff    # [win]
        - hdf5       # [win]
        - libpng     # [win]
        - zlib       # [win]
      missing_dso_whitelist:     # [osx]
        - "*"   # [osx]
    run_exports:
      # We are cautiously optimistic here that patch-level updates won't break
      # ABI. However, it sounds like upstream won't guarantee *any* sort of
      # binary compatibility any longer. See also
      #
      #     https://github.com/opencv/opencv/wiki/OE-4.-OpenCV-4
      #
      - {{ pin_subpackage('opencv', max_pin='x.x') }}
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - ninja
        - pkg-config
        - {{ cdt('mesa-libGL-devel') }}         # [aarch64]
        - {{ cdt('mesa-libEGL-devel') }}        # [aarch64]
      host:
        - cmake
        - _openmp_mutex         # [linux]
        - eigen
        - ffmpeg                # [linux64]
        - freetype              # [not win]
        - glib                  # [not ppc64le]
        - gst-plugins-base      # [not (win or ppc64le)]
        - gstreamer             # [not (win or ppc64le)]
        - gst-plugins-base ==1.18.5      # [win]
        - gstreamer ==1.18.5             # [win]
        - harfbuzz              # [not win]
        - hdf5
        - jpeg                  # [not win]
        - openjpeg              # [not (arm64 or win)]
        - openblas-devel        # [x86_64 and not win]
        - libpng
        - libprotobuf           # [linux64 or win]
        - libtiff
        - libwebp-base          # [win or linux64]
        - numpy {{ numpy }}
        - python
        - qt ==5.9.7            # [(x86_64 or win) and not ppc64le]
        - qt ==5.15.2           # [arm64 or aarch64]
        - zlib
      run:
        - _openmp_mutex         # [linux]
        - eigen
        - ffmpeg                # [linux64]
        - freetype              # [not win]
        - glib                  # [not ppc64le]
        - gst-plugins-base      # [not (win or ppc64le)]
        - gstreamer             # [not (win or ppc64le)]
        - gst-plugins-base ==1.18.5      # [win]
        - gstreamer ==1.18.5             # [win]
        - harfbuzz              # [not win]
        - hdf5
        - jpeg                  # [not win]
        - openjpeg              # [not (arm64 or win)]
        - libopenblas           # [x86_64 and not win]
        - libpng
        - libtiff
        - libwebp-base          # [win or linux64]
        - numpy {{ numpy }}
        - python
        - qt ==5.9.7            # [(x86_64 or win) and not ppc64le]
        - qt ==5.15.2           # [arm64 or aarch64]
        - zlib
    test:
      requires:
        - {{ compiler('cxx') }}
        - cmake
        - python
        - numpy
        - ninja
        - {{ cdt('libselinux-devel') }}      # [linux]
        - {{ cdt('libx11-devel') }}          # [linux]
        - {{ cdt('libxau-devel') }}          # [linux]
        - {{ cdt('libxcb') }}                # [linux]
        - {{ cdt('libxdamage-devel') }}      # [linux]
        - {{ cdt('libxext-devel') }}         # [linux]
        - {{ cdt('libxfixes-devel') }}       # [linux]
        - {{ cdt('libxi-devel') }}           # [linux]
        - {{ cdt('libxrender-devel') }}      # [linux]
        - {{ cdt('libxxf86vm') }}            # [linux]
        - {{ cdt('mesa-dri-drivers') }}      # [linux]
        - {{ cdt('mesa-libgl-devel') }}      # [linux]
        - {{ cdt('xorg-x11-proto-devel') }}  # [linux]
      files:
        - test-cmake/CMakeLists.txt
        - test-cmake/DisplayImage.cpp
        - test.cpp
      commands:
        - pushd test-cmake
        - cmake . -GNinja -DCMAKE_BUILD_TYPE=Release
        - cmake --build . --verbose
        - popd
        # Verify dynamic libraries.
        # "bioinspired", Not working in 3.1.0
        {% set opencv_libs = [
             "aruco",
             "bgsegm",
             "calib3d",
             "ccalib",
             "core",
             "datasets",
             "dpm",                               # [linux64]
             "face",                              # [linux64]
             "features2d",
             "flann",
             "fuzzy",
             "highgui",
             "imgcodecs",
             "imgproc",
             "line_descriptor",
             "ml",
             "objdetect",                        # [linux64]
             "optflow",
             "phase_unwrapping",
             "photo",
             "plot",
             "reg",
             "rgbd",
             "saliency",
             "shape",
             "stereo",
             "stitching",
             "structured_light",
             "superres",
             "surface_matching",
             "text",                             # [linux64]
             "tracking",
             "video",
             "videoio",
             "videostab",
             "xfeatures2d",
             "ximgproc",
             "xobjdetect",                       # [linux64]
             "xphoto",
        ] %}
        {% for each_opencv_lib in opencv_libs %}
        - test -f ${CONDA_PREFIX}/lib/libopencv_{{ each_opencv_lib }}.dylib                        # [osx]
        - test -f ${CONDA_PREFIX}/lib/libopencv_{{ each_opencv_lib }}.so                           # [linux]
        - if not exist %CONDA_PREFIX%\\Library\\bin\\opencv_{{ each_opencv_lib }}{{ version|replace(".","") }}.dll exit 1 # [win]
        {% endfor %}

  # This recipe has merged the outputs for the compiled libraries with the
  # python bindings that used to be vendored as libopencv and py-opencv. This
  # was done to try to improve maintainibility. The following two output
  # sections provide no files other than those already in the opencv package.
  # These "virtual" packages provide backwards compatibility with recipes
  # depending on either of the two old packages.
  - name: libopencv
    script: install-nothing.sh                  # [not win]
    script: install-nothing.bat                 # [win]
    version: {{ version }}
    build:
      number: {{ build_num }}
      missing_dso_whitelist:     # [osx]
        - "*"   # [osx]
    requirements:
      host:
        - opencv =={{ version }}
      run:
        - opencv =={{ version }}


  - name: py-opencv
    script: install-nothing.sh                  # [not win]
    script: install-nothing.bat                 # [win]
    version: {{ version }}
    build:
      number: {{ build_num }}
      missing_dso_whitelist:     # [osx]
        - "*"   # [osx]
    requirements:
      host:
        - opencv =={{ version }}
      run:
        - opencv =={{ version }}

about:
  home: https://opencv.org/
  license: Apache-2.0
  license_family: Apache
  summary: Computer vision and machine learning software library.
  description: |
    OpenCV (Open Source Computer Vision Library) includes several hundreds of computer vision algorithms.
    It has a modular structure,which means that the package includes several shared or static libraries.
  doc_url: https://docs.opencv.org/
  doc_source_url: https://github.com/opencv/opencv/tree/master/doc
  dev_url: https://github.com/opencv/opencv/
