# -*- 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           github 1.0
PortGroup           mpi 1.0
PortGroup           muniversal 1.0

github.setup        hypre-space hypre 2.32.0 v
revision            0
categories          math
license             LGPL-2.1
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         HYPRE is a linear solver
long_description    HYPRE is a library for solving large, sparse linear \
                    systems of equations on massively parallel computers.

checksums           rmd160  3065e91c7a70883f81839b95f4289d8d806811fc \
                    sha256  2277b6f01de4a7d0b01cfe12615255d9640eaa02268565a7ce1a769beab25fa1 \
                    size    7512442
github.tarball_from archive

cmake.source_dir    ${worksrcpath}/src

depends_build-append \
                    port:grep

# Only some components need this, but ensure we use a compiler that builds everything:
compiler.cxx_standard 2017

configure.args-append \
                    -DCMAKE_INSTALL_INCLUDEDIR=${prefix}/include/HYPRE \
                    -DHYPRE_BUILD_EXAMPLES=OFF \
                    -DHYPRE_BUILD_TESTS=OFF \
                    -DHYPRE_ENABLE_SHARED=ON \
                    -DHYPRE_ENABLE_BIGINT=OFF \
                    -DHYPRE_ENABLE_MIXEDINT=OFF \
                    -DHYPRE_ENABLE_SINGLE=OFF \
                    -DHYPRE_ENABLE_LONG_DOUBLE=OFF \
                    -DHYPRE_ENABLE_COMPLEX=OFF \
                    -DHYPRE_ENABLE_HOPSCOTCH=OFF \
                    -DHYPRE_ENABLE_HYPRE_BLAS=ON \
                    -DHYPRE_ENABLE_HYPRE_LAPACK=ON \
                    -DHYPRE_ENABLE_FEI=OFF \
                    -DHYPRE_ENABLE_ONEMKLSPARSE=OFF \
                    -DHYPRE_ENABLE_ONEMKLBLAS=OFF \
                    -DHYPRE_ENABLE_ONEMKLRAND=OFF \
                    -DHYPRE_USING_HOST_MEMORY=ON \
                    -DHYPRE_WITH_CALIPER=OFF \
                    -DHYPRE_WITH_CUDA=OFF \
                    -DHYPRE_WITH_GPU_AWARE_MPI=OFF \
                    -DHYPRE_WITH_MPI=ON \
                    -DHYPRE_WITH_OPENMP=OFF \
                    -DHYPRE_WITH_SUPERLU=OFF \
                    -DHYPRE_WITH_DSUPERLU=OFF \
                    -DHYPRE_WITH_SYCL=OFF \
                    -DHYPRE_WITH_UMPIRE=OFF

if {![mpi_variant_isset]} {
    configure.args-replace \
                    -DHYPRE_WITH_MPI=ON -DHYPRE_WITH_MPI=OFF
} else {
    if {${os.platform} eq "darwin" && ${os.arch} eq "powerpc"} {
        mpi.setup   require \
                    -gcc44 -gcc45 -gcc46 -gcc47 -gcc48 -gcc49 -gcc5 \
                    -clang -fortran
    } else {
        mpi.setup   require \
                    -gcc44 -gcc45 -gcc46 -gcc47 -gcc48 -gcc49 -gcc5
    }
}

variant longindex description {Build with 64-bit ints} {
    configure.args-replace \
                    -DHYPRE_ENABLE_BIGINT=OFF -DHYPRE_ENABLE_BIGINT=ON
}

variant openmp description {Build with OpenMP} {
    compiler.openmp_version 3.0
    configure.args-replace \
                    -DHYPRE_WITH_OPENMP=OFF -DHYPRE_WITH_OPENMP=ON

    if {[string match *clang* ${configure.compiler}]} {
        configure.ldflags-append \
                    -L${prefix}/lib/libomp -lomp
    }
}

default_variants    +openmp

# FIXME: tests target is broken: https://github.com/hypre-space/hypre/issues/928
variant tests description {Enable testing} {
    configure.pre_args-replace \
                    -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON \
                    -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=OFF

    configure.args-replace \
                    -DHYPRE_BUILD_TESTS=OFF -DHYPRE_BUILD_TESTS=ON

    test.run        yes
}
