# -*- 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             2.22.1
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  44050230ee31640dc1f0176f110cb9795f138a1a \
                    sha256  daf53fe96783043ca33151a3851d054a826fab8d9a173e6bcbbedd4a7eabf5b1 \
                    size    1365626

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