# -*- 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

PortSystem          1.0
PortGroup           cmake 1.1
PortGroup           mpi 1.0
PortGroup           github 1.0

github.setup        mariusmuja flann 1.9.2
revision            3
categories          science devel
maintainers         nomaintainer
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.
license             BSD

checksums           rmd160  a942fa80ed1c31fbdeafbf6bffdbcfa6b88cdfed \
                    sha256  d41caad0048f3cff7ecdff256abd6286113f982da56ce08b2fcd8419d2f0ba8a \
                    size    34642093

depends_build-append \
                    port:pkgconfig
depends_lib-append  port:hdf5 \
                    port:lz4

patchfiles          patch-src-python-CMakeLists.txt.diff
mpi.setup

configure.args-append \
                    ${distname} \
                    -DUSE_MPI=OFF \
                    -DUSE_OPENMP=ON \
                    -DBUILD_C_BINDINGS=ON \
                    -DBUILD_CUDA_LIB=OFF \
                    -DBUILD_DOC=OFF \
                    -DBUILD_EXAMPLES=OFF \
                    -DBUILD_MATLAB_BINDINGS=OFF \
                    -DBUILD_TESTS=OFF

if {[ mpi_variant_isset ]} {
    configure.args-replace      -DUSE_MPI=OFF \
                                -DUSE_MPI=ON
}

compiler.cxx_standard 2011

set pythons_suffixes {27 37 38 39 310 311}

set pythons_ports {}
foreach s ${pythons_suffixes} {
    lappend pythons_ports python${s}
}

proc python_dir {} {
    global pythons_suffixes
    foreach s ${pythons_suffixes} {
        if {[variant_isset python${s}]} {
            set p python[string index ${s} 0].[string range ${s} 1 end]
            return [file normalize [exec ${p} -c "import sys; print(sys.prefix)"]/lib/${p}]
        }
    }
    error "Python support not enabled."
}

foreach s ${pythons_suffixes} {
    set p python${s}
    set v [string index ${s} 0].[string range ${s} 1 end]
    set i [lsearch -exact ${pythons_ports} ${p}]
    set c [lreplace ${pythons_ports} ${i} ${i}]
    variant ${p} description "Use Python ${v} for python bindings" conflicts {*}${c} "
        depends_lib-append      port:${p}
        configure.args-append   -DPYTHON_EXECUTABLE=${prefix}/bin/python${v}
        post-patch {
            reinplace \"s|@@PREFIX@@|${destroot}${prefix}|g\" ${patch.dir}/src/python/CMakeLists.txt
            set pylibdir \[python_dir\]
            reinplace \"s|@@PYTHON_LIB@@|${destroot}\${pylibdir}|g\" ${patch.dir}/src/python/CMakeLists.txt
        }
    "
}
