# -*- 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           active_variants 1.1
PortGroup           linear_algebra 1.0

name                oof2
version             2.4.0
revision            0

license             public-domain
categories          science
maintainers         {@snarkhunter nist.gov:stephen.langer} \
                    nist.gov:oof_manager openmaintainer

description         Image-based finite element analysis of materials
long_description    OOF2 computes properties of materials with complex \
                    microstructures via image-based finite element analysis.

homepage            https://www.ctcms.nist.gov/oof/oof2
master_sites        ${homepage}/source

checksums           rmd160 0d5e93bf0498f8843f575eae1be931e995dbdf1d \
                    sha256 eb8f4690396e46f70888912fa31902baf15566d0a3ba5b1c7faa079d3bddfafd \
                    size 29174946

compiler.cxx_standard 2017

livecheck.type      regex
livecheck.url       ${homepage}
livecheck.regex     "source/oof2-(\\d+(?:\\.\\d+)*).tar.gz"

# fails to build on macOS < 10.12
compiler.blacklist-append {clang < 900}

depends_build       path:bin/cmake:cmake port:pkgconfig port:swig-python
depends_run         port:adwaita-icon-theme

pre-configure {
    # Link to chosen BLAS/LAPACK
    configure.args-append   ${cmake_linalglib}
}

# Create a variant for each supported python version
set python_versions {310 311 312 313 314}
foreach v ${python_versions} {
    # Create a list of the other python versions, which this variant
    # is incompatible with.
    set minor [string range ${v} 1 end]
    set conflictswith {}
    foreach vv ${python_versions} {
        if {${vv} != ${v}} {
            lappend conflictswith python${vv}
        }
    }
    variant python${v} description "Use Python 3.${minor}" \
        conflicts {*}${conflictswith} \
        [ subst {
            depends_lib-append port:oofcanvas port:py${v}-matplotlib
            configure.args-append \
                -DOOF2_PYTHON_VERSION=3.$minor \
                -DOOF2_SYSTEM_INSTALL=ON
            require_active_variants oofcanvas {python${v} {numpy}}
        }]
}

# python314 is the default variant if no other python variant is set
set vactive 0
foreach v ${python_versions} {
    if [variant_isset python$v] {
        set vactive 1
    }
}
if { !$vactive } {
    default_variants +python314
}

variant dev description "Install development files for building extensions" {
    configure.args-append -DOOF2_DEV_INSTALL=ON
}

