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

compilers.choose    cc cxx

name                ensmallen
version             3.10.0
revision            0
categories          math devel science
license             BSD
platforms           any
maintainers         {takeshi @tenomoto} openmaintainer
description         flexible C++ library for efficient numerical optimization
long_description \
    ${name} provides a simple set of abstractions \
    for writing an objective function to optimize. \
    It also provides a large set of standard and cutting-edge optimizers \
    that can be used  for virtually any numerical optimization task. \
    These include full-batch gradient descent techniques, \
    small-batch techniques, gradient-free optimizers, and constrained optimization.
homepage            https://ensmallen.org
master_sites        ${homepage}/files

checksums           rmd160  71dec3bdd2009c87f021aa77d03d1c0216a4af75 \
                    sha256  248e2036856f7aa8fab34ca02fa3a79b2c9af20f53b1d26e3de939d150dcbb3a \
                    size    1399865

# https://trac.macports.org/ticket/69317
if {![variant_isset tests]} {
    supported_archs noarch
}

depends_lib         port:armadillo

compiler.cxx_standard 2011

configure.args-append \
                    -DARMADILLO_INCLUDE_DIR=${prefix}/include \
                    -DARMADILLO_LIBRARY=${prefix}/lib/libarmadillo.dylib

variant tests description "Enable testing" {
    build.target    ensmallen_tests

    pre-test {
        # This is needed: https://github.com/mlpack/ensmallen/issues/389
        if {${os.platform} eq "darwin" && ${configure.cxx_stdlib} ne "libc++"} {
            move    ${cmake.build_dir}/ensmallen_tests \
                    ${cmake.build_dir}/ensmallen_tests-orig

            set  wrapper    [open "${cmake.build_dir}/ensmallen_tests" w 0755]
            puts ${wrapper} "#!/bin/bash"
            puts ${wrapper} ""
            puts ${wrapper} {if [ -n "$DYLD_LIBRARY_PATH" ]; then}
            puts ${wrapper} "   DYLD_LIBRARY_PATH=${prefix}/lib/libgcc:\${DYLD_LIBRARY_PATH}"
            puts ${wrapper} {else}
            puts ${wrapper} "   DYLD_LIBRARY_PATH=${prefix}/lib/libgcc"
            puts ${wrapper} {fi}
            puts ${wrapper} {export DYLD_LIBRARY_PATH}
            puts ${wrapper} ""
            puts ${wrapper} {exec "${0}-orig" "$@"}
            close $wrapper
        }
    }

    test.run        yes
    test.cmd        ./ensmallen_tests
    test.post_args  --durations yes
    test.target
}
