# $Id: Portfile 90786 2012-03-14 18:22:07Z mmoll@macports.org $

PortSystem 1.0
PortGroup cmake 1.0
name                flann
version             1.7.1
revision            2
categories          science devel
maintainers         mmoll
description         Fast Library for Approximate Nearest Neighbors
long_description    FLANN is a library for performing fast approximate \
                    nearest neighbor searches in high dimensional spaces. \
                    It contains a collection of algorithms we found to \
                    work best for nearest neighbor search and a system \
                    for automatically choosing the best algorithm and \
                    optimum parameters depending on the dataset.
homepage            http://people.cs.ubc.ca/~mariusm/index.php/FLANN/FLANN
platforms           darwin
license             BSD
master_sites        http://people.cs.ubc.ca/~mariusm/uploads/FLANN/
distname            ${name}-${version}-src
use_zip             yes
extract.mkdir       yes
checksums           md5     1832b560cce9cde1c18ad1c7e907ae76 \
                    sha1    4f3cef9b4f171b1ee4a98f4f684c350c3022e9b2 \
                    rmd160  c48f6de9d3c1c87a446a4f3f0353ff02f4fe6506
depends_lib         port:hdf5-18 port:tbb
patchfiles          patch-src-python-CMakeLists.txt.diff
patch.dir           ${worksrcpath}/${worksrcdir}

# MPI support is automatically disabled if hdf5-18 is installed without the +openmpi variant
configure.args-append ${distname} -DBUILD_MATLAB_BINDINGS=OFF -DUSE_MPI=ON -DBUILD_CUDA_LIB=OFF \
                    -DMPIEXEC=${prefix}/lib/openmpi/bin/mpiexec \
                    -DMPI_COMPILER=${prefix}/lib/openmpi/bin/mpic++

variant python26 description {Use python2.6 for python bindings} conflicts python27 python31 python32 {
    depends_lib-append      port:python26
    configure.args-append   -DPYTHON_EXECUTABLE=${prefix}/bin/python2.6
    post-patch {
        reinplace "s|@@PREFIX@@|${destroot}${prefix}|g" ${patch.dir}/src/python/CMakeLists.txt
        reinplace "s|@@PYTHON_LIB@@|${destroot}${prefix}/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6|g" ${patch.dir}/src/python/CMakeLists.txt
    }
}
variant python27 description {Use python2.7 for python bindings} conflicts python26 python31 python32 {
    depends_lib-append      port:python27
    configure.args-append   -DPYTHON_EXECUTABLE=${prefix}/bin/python2.7
    post-patch {
        reinplace "s|@@PREFIX@@|${destroot}${prefix}|g" ${patch.dir}/src/python/CMakeLists.txt
        reinplace "s|@@PYTHON_LIB@@|${destroot}${prefix}/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7|g" ${patch.dir}/src/python/CMakeLists.txt
    }
}
variant python31 description {Use python3.1 for python bindings} conflicts python26 python27 python32 {
    depends_lib-append      port:python31
    configure.args-append   -DPYTHON_EXECUTABLE=${prefix}/bin/python3.1
    post-patch {
        reinplace "s|@@PREFIX@@|${destroot}${prefix}|g" ${patch.dir}/src/python/CMakeLists.txt
        reinplace "s|@@PYTHON_LIB@@|${destroot}${prefix}/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1|g" ${patch.dir}/src/python/CMakeLists.txt
    }
}
variant python32 description {Use python3.2 for python bindings} conflicts python26 python27 python31 {
    depends_lib-append      port:python32
    configure.args-append   -DPYTHON_EXECUTABLE=${prefix}/bin/python3.2
    post-patch {
        reinplace "s|@@PREFIX@@|${destroot}${prefix}|g" ${patch.dir}/src/python/CMakeLists.txt
        reinplace "s|@@PYTHON_LIB@@|${destroot}${prefix}/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2|g" ${patch.dir}/src/python/CMakeLists.txt
    }
}

variant cuda description {Enable CUDA support} {
    configure.args-delete -DBUILD_CUDA_LIB=OFF
    configure.args-append -DBUILD_CUDA_LIB=ON
}
# CUDA is enabled by default (compilation won't fail if CUDA is not installed),
# but people with broken CUDA installs can disable the CUDA bindings.
default_variants +cuda

livecheck.type      regex
livecheck.url       ${homepage}
livecheck.regex     Version (\[0-9.\]+)
