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

# MAP_ANONYMOUS
legacysupport.newest_darwin_requires_legacy 14

github.setup        LLNL CHAI 2024.07.0 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
name                chai
revision            0
categories          devel
license             BSD
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         Copy-hiding array abstraction to automatically migrate data between memory spaces
long_description    CHAI is a library that handles automatic data migration to different memory spaces \
                    behind an array-style interface. It was designed to work with RAJA and integrates with it. \
                    CHAI could be used with other C++ abstractions, as well.

fetch.type          git

post-fetch {
    system -W ${worksrcpath} "git submodule update --init --recursive"
}

if {${os.platform} eq "darwin" && ${os.arch} eq "powerpc"} {
    mpi.setup       require require_fortran \
                    -gcc44 -gcc45 -gcc46 -gcc47 -gcc48 -gcc49 -gcc5 -gcc6 \
                    -clang -fortran
} else {
    mpi.setup       require require_fortran \
                    -gcc44 -gcc45 -gcc46 -gcc47 -gcc48 -gcc49 -gcc5 -gcc6 \
                    -clang18
}

set port_libfmt     libfmt11

depends_lib-append  port:cppcheck \
                    path:bin/git:git \
                    port:${port_libfmt} \
                    port:raja \
                    port:uncrustify

# Configure fails to work correctly with an external Camp: https://github.com/LLNL/CHAI/issues/231
# configure.args-append \
#                     -Dcamp_DIR=${prefix}
# Since Raja already installs Camp, we have to patch sources to avoid a conflicting copy.
# For now, keeping dylib is fine though, since Raja builds statically.
patchfiles-append   patch-avoid-dupe-camp.diff

# https://trac.macports.org/ticket/70176
compiler.blacklist-append \
                    {macports-clang-1[8-9]}

# Bump C++ to 2017: https://github.com/LLNL/CHAI/issues/220
compiler.cxx_standard   2017
compiler.openmp_version 4.0

# Fortran disabled for Umpire due to: https://github.com/LLNL/Umpire/issues/833
configure.args-append \
                    -DBLT_CXX_STD="c++17" \
                    -DBUILD_SHARED_LIBS=ON \
                    -DCHAI_ENABLE_BENCHMARKS=OFF \
                    -DCHAI_ENABLE_CUDA=OFF \
                    -DCHAI_ENABLE_DOCS=OFF \
                    -DCHAI_ENABLE_EXAMPLES=OFF \
                    -DCHAI_ENABLE_GMOCK=OFF \
                    -DCHAI_ENABLE_HIP=OFF \
                    -DCHAI_ENABLE_MPI=ON \
                    -DCHAI_ENABLE_OPENMP=ON \
                    -DCHAI_ENABLE_RAJA_PLUGIN=ON \
                    -DCHAI_ENABLE_REPRODUCERS=ON \
                    -DCHAI_ENABLE_TESTS=ON \
                    -DENABLE_ASTYLE=OFF \
                    -DENABLE_CPPCHECK=ON \
                    -DENABLE_CLANGTIDY=OFF \
                    -DENABLE_EXAMPLES=OFF \
                    -DENABLE_FORTRAN=ON \
                    -DENABLE_FRUIT=ON \
                    -DENABLE_FRUIT_MPI=ON \
                    -DENABLE_GIT=ON \
                    -DENABLE_MPI=ON \
                    -DENABLE_OPENMP=ON \
                    -DENABLE_SPHINX=OFF \
                    -DENABLE_TESTS=ON \
                    -DENABLE_UNCRUSTIFY=ON \
                    -DENABLE_VALGRIND=OFF \
                    -DENABLE_YAPF=OFF \
                    -Dfmt_DIR=${prefix}/lib/${port_libfmt}/cmake \
                    -DFMT_INSTALL=OFF \
                    -DRAJA_DIR=${prefix} \
                    -DUMPIRE_ENABLE_C=ON \
                    -DUMPIRE_ENABLE_FORTRAN=OFF

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

post-destroot {
    # We already have these with Raja.
    delete ${destroot}${prefix}/lib/cmake/camp
}

test.run            yes
