# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 93038 2012-05-14 09:34:46Z raphael@macports.org $

PortSystem                      1.0
PortGroup                       cmake 1.0

name                            opencv
version                         2.4.0
categories                      graphics science
license                         BSD
platforms                       darwin
maintainers                     nomaintainer

description                     Intel(R) Open Source Computer Vision Library

long_description                opencv is a library that is mainly aimed at real time \
                                computer vision. Some example areas would be \
                                Human-Computer Interaction (HCI), Object Identification, \
                                Segmentation and Recognition, Face Recognition, Gesture \
                                Recognition, Motion Tracking, Ego Motion, Motion \
                                Understanding, Structure From Motion (SFM), and Mobile \
                                Robotics.

homepage                        http://opencv.willowgarage.com/wiki/
master_sites                    sourceforge:project/opencvlibrary/opencv-unix/${version}
use_bzip2                       yes
distname                        OpenCV-${version}

checksums                       rmd160  49aae35880d3765676a9f556bd8b152c45acafd7 \
                                sha256  3b5fedb2fc6ad0aa1509676468f571ba21456679e7d48a8242a096d62e2c6ac9

depends_build-append            port:pkgconfig

depends_lib-append              port:zlib \
                                path:lib/libavcodec.dylib:ffmpeg \
                                port:libpng \
                                port:tiff \
                                port:jasper \
                                port:jpeg \
                                port:bzip2 \
                                port:openexr \
                                port:ilmbase \
                                port:eigen3

patchfiles                      patch-fix_dirname_case.diff \
                                patch-install_name.diff

if {[variant_isset universal] && [variant_exists universal]} {
    patchfiles-append           patch-pch-CMakeLists.txt.diff
}

configure.args-append           -DBUILD_NEW_PYTHON_SUPPORT=OFF \
                                -DBUILD_EXAMPLES=ON \
                                -DINSTALL_C_EXAMPLES=ON \
                                -DBZIP2_LIBRARIES=${prefix}/lib/libbz2.dylib \
                                -DZLIB_LIBRARY=${prefix}/lib/libz.dylib \
                                -DWITH_OPENEXR=ON \
                                -DWITH_1394=OFF \
                                -DWITH_EIGEN=ON \
                                -DEIGEN_INCLUDE_PATH=${prefix}/include/eigen3 \
                                -DBUILD_JASPER=OFF \
                                -DBUILD_JPEG=OFF \
                                -DBUILD_PNG=OFF \
                                -DBUILD_TIFF=OFF \
                                -DBUILD_ZLIB=OFF

# gcc-4.0 exits with a bus error
if {${configure.compiler} == "gcc-4.0"} {
    configure.compiler gcc-4.2
    if {![file executable ${configure.cc}]} {
        depends_build-append port:apple-gcc42
        depends_skip_archcheck-append apple-gcc42
        configure.compiler apple-gcc-4.2
    }
}

platform darwin {
    if {${os.major} <= 9} {
        # Video Decode Acceleration Framework is not available
        patchfiles-append       patch-highgui_CMakeLists.txt.diff
    }
}

post-destroot {
    xinstall -d ${destroot}${prefix}/lib/cmake
    move ${destroot}${prefix}/share/OpenCV/OpenCVConfig-version.cmake \
        ${destroot}${prefix}/share/OpenCV/OpenCVConfig.cmake \
        ${destroot}${prefix}/lib/cmake/
}

variant dc1394 description {Use libdc1394 for FireWire camera. Breaks compatibility with Apple iSight FireWire camera.} {
    depends_lib-append          port:libdc1394
    configure.args-delete       -DWITH_1394=OFF
    configure.args-append       -DWITH_1394=ON \
                                -DHAVE_1394=ON
}

variant qt4 description {Use qt4 backend for graphical interface.} {
    PortGroup                   qt4 1.0
    configure.args-append       -DWITH_QT=ON
}

variant python26 conflicts python27 description {Add Python 2.6 bindings} {
    depends_lib-append          port:python26 \
                                port:py26-numpy
    configure.args-delete       -DBUILD_NEW_PYTHON_SUPPORT=OFF
    configure.args-append       -DINSTALL_PYTHON_EXAMPLES=ON \
                                -DBUILD_NEW_PYTHON_SUPPORT=ON \
                                -DPYTHON_EXECUTABLE=${prefix}/bin/python2.6 \
                                -DPYTHON_LIBRARY=${prefix}/lib/libpython2.6.dylib \
                                -DPYTHON_INCLUDE_DIR=${frameworks_dir}/Python.framework/Versions/2.6/Headers \
                                -DPYTHON_PACKAGES_PATH=${frameworks_dir}/Python.framework/Versions/2.6/lib/python2.6/site-packages
}

variant python27 conflicts python26 description {Add Python 2.7 bindings} {
    depends_lib-append          port:python27 \
                                port:py27-numpy
    configure.args-delete       -DBUILD_NEW_PYTHON_SUPPORT=OFF
    configure.args-append       -DINSTALL_PYTHON_EXAMPLES=ON \
                                -DBUILD_NEW_PYTHON_SUPPORT=ON \
                                -DPYTHON_EXECUTABLE=${prefix}/bin/python2.7 \
                                -DPYTHON_LIBRARY=${prefix}/lib/libpython2.7.dylib \
                                -DPYTHON_INCLUDE_DIR=${frameworks_dir}/Python.framework/Versions/2.7/Headers \
                                -DPYTHON_PACKAGES_PATH=${frameworks_dir}/Python.framework/Versions/2.7/lib/python2.7/site-packages
}

variant tbb description {Use Intel TBB} {
    depends_lib-append          port:tbb
    configure.args-append       -DWITH_TBB=ON \
                                -DHAVE_TBB=ON \
                                -DTBB_INCLUDE_DIRS=${prefix}/include \
                                -DOPENCV_LINKER_LIBS="-ltbb -ltbbmalloc"
}

livecheck.type                  sourceforge
livecheck.name                  opencvlibrary
livecheck.regex                 /OpenCV-(\[0-9a-z.\]+)${extract.suffix}
