# -*- 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               mpi       1.0
PortGroup               cmake     1.1
PortGroup               legacysupport 1.1

# MEDfileExist.c: error: implicit declaration of function 'strndup' [-Wimplicit-function-declaration]
legacysupport.newest_darwin_requires_legacy 10

name                    libmed
version                 4.1.1
revision                5
categories              science devel
maintainers             {mcalhoun @MarcusCalhoun-Lopez} openmaintainer
license                 GPL-3+ LGPL-3+
homepage                https://web.archive.org/web/20220124071248/https://www.salome-platform.org/user-section/about/med

description             a library to store and exchange meshed data or computation results

long_description        MED (Modeling and Exchange of Data) is {*}${description}.

master_sites            macports_distfiles
distname                med-${version}
worksrcdir              ${distname}_SRC

checksums               rmd160  2e0a189cb4b5d72ae88c8e8fb26a61821e4e60be \
                        sha256  dc2b5d54ebf0666e3ff2e974041d2ab0da906061323537023ab165d573389dd0 \
                        size    50506725

patchfiles              patch-hdf5-1.12.diff \
                        patch-test10.diff

# error: cinttypes: No such file or directory
compiler.c_standard     2011

mpi.setup               require_fortran
if {[mpi_variant_isset]} {
    configure.args-append -DMEDFILE_USE_MPI=ON
}

configure.args-append   -DMEDFILE_BUILD_TESTS=OFF

depends_lib-append      port:hdf5
mpi.enforce_variant     hdf5

variant python311 conflicts python310 description {add support for Python 3.11} {
    set python.branch       3.11
    depends_build-append    port:swig-python
    configure.args-append   -DMEDFILE_BUILD_PYTHON=ON \
                            -DPYTHON_EXECUTABLE=${frameworks_dir}/Python.framework/Versions/${python.branch}/bin/python${python.branch} \
                            -DPYTHON_LIBRARY=${frameworks_dir}/Python.framework/Versions/${python.branch}/lib/libpython${python.branch}.dylib \
                            -DPYTHON_INCLUDE_DIR=${frameworks_dir}/Python.framework/Versions/${python.branch}/Headers
}

variant python310 conflicts python311 description {add support for Python 3.10} {
    set python.branch       3.10
    depends_build-append    port:swig-python
    configure.args-append   -DMEDFILE_BUILD_PYTHON=ON \
                            -DPYTHON_EXECUTABLE=${frameworks_dir}/Python.framework/Versions/${python.branch}/bin/python${python.branch} \
                            -DPYTHON_LIBRARY=${frameworks_dir}/Python.framework/Versions/${python.branch}/lib/libpython${python.branch}.dylib \
                            -DPYTHON_INCLUDE_DIR=${frameworks_dir}/Python.framework/Versions/${python.branch}/Headers
}

post-destroot {
    # install Python files in the correct directory (for macOS)
    foreach d [glob -type d -nocomplain -tails -directory ${destroot}${prefix}/lib python*] {
        set python.branch   [string range ${d} 6 end]
        xinstall -d -m 0755 ${destroot}${frameworks_dir}/Python.framework/Versions/${python.branch}/lib
        move                ${destroot}${prefix}/lib/python${python.branch} \
                            ${destroot}${frameworks_dir}/Python.framework/Versions/${python.branch}/lib
    }
}

variant tests description {Enable tests} {
    test.run                yes
    configure.args-delete   -DMEDFILE_BUILD_TESTS=OFF
    test.args-append        DYLD_LIBRARY_PATH=${cmake.build_dir}/src
    patchfiles-append       patch-python_test.diff
    post-patch {
        reinplace           "s|__MACPORTS_DYLD_LIBRARY_PATH__|${cmake.build_dir}/src|g" \
                            ${worksrcpath}/tests/python/CMakeLists.txt
    }
    pre-test {
        foreach so [glob -type f -nocomplain -tails -directory ${cmake.build_dir}/python *.so] {
            ln -s ../${so} ${cmake.build_dir}/python/med/${so}
        }
    }
}

livecheck.type          none
