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

name                oof2
version             2.3.3
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 568cd6ba0de1ebc325bd56f31f07da4b76516c27 \
                    sha256 5f996050ccec7173a86e1554831a94e360d4712349e71183aee4cdf24f2dcb71 \
                    size 14958599

# To be dropped once bundled Eigen is updated.
# Upstream fixed this bug in https://gitlab.com/libeigen/eigen/-/merge_requests/1150
patchfiles-append   patch-disable-broken-altivec-in-eigen.diff

compiler.cxx_standard 2011

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

configure.args-append -DOOF2_SWIG_VERSION=4.1

# Create a variant for each supported python version
set python_versions {310 311 312}
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
            configure.args-append \
                -DOOF2_PYTHON3_VERSION=3.$minor \
                -DOOF2_SYSTEM_INSTALL=ON
            require_active_variants oofcanvas {python${v} magick} {numpy}
        }]
}

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

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