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

# clock_gettime
# On <10.15 built-in libc++ has no support for std::filesystem
legacysupport.use_mp_libcxx                 yes
legacysupport.newest_darwin_requires_legacy 18

github.setup        pika-org pika 0.30.1
revision            0
categories          devel parallel
license             Boost-1
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         C++ library for concurrency and parallelism
long_description    pika is a C++ library for concurrency and parallelism. \
                    It implements senders/receivers for CPU thread pools, MPI and CUDA.
checksums           rmd160  56dd621b8cded126322d8fbff94ef5878acf8914 \
                    sha256  b0f3689a3edd30f8d674e19b5134fc5013813f843c45797c1015163e51989ac0 \
                    size    1179489
github.tarball_from archive

# Prefer a version with libcontext working across all archs (ppc64 is still not fixed):
boost.version       1.81

# https://github.com/pika-org/pika/issues/1236
patchfiles-append   patch-fix-finding-boost.diff

# Keep in sync with spdlog port:
set port_libfmt     libfmt10
cmake.module_path-append \
                    ${prefix}/lib/${port_libfmt}/cmake

depends_lib-append  port:hwloc \
                    port:${port_libfmt} \
                    port:spdlog

if {${os.platform} eq "darwin" && ${os.arch} eq "powerpc"} {
    mpi.setup       require -gcc6 -gcc7 -gcc8 -clang -fortran
} else {
    mpi.setup       require -gcc6 -gcc7 -gcc8
}

compiler.thread_local_storage yes
compiler.cxx_standard 2017
compiler.blacklist-append \
                    {clang < 1300} {macports-clang-[4-6].0}

configure.args-append \
                    -DPIKA_WITH_COMPILER_WARNINGS=ON \
                    -DPIKA_WITH_COMPILER_WARNINGS_AS_ERRORS=OFF \
                    -DPIKA_WITH_CUDA=OFF \
                    -DPIKA_WITH_DEPRECATION_WARNINGS=OFF \
                    -DPIKA_WITH_DISABLED_SIGNAL_EXCEPTION_HANDLERS=OFF \
                    -DPIKA_WITH_EXAMPLES=OFF \
                    -DPIKA_WITH_GPU_SUPPORT=OFF \
                    -DPIKA_WITH_HIDDEN_VISIBILITY=OFF \
                    -DPIKA_WITH_HIP=OFF \
                    -DPIKA_WITH_ITTNOTIFY=OFF \
                    -DPIKA_WITH_LOGGING=ON \
                    -DPIKA_WITH_MPI=ON \
                    -DPIKA_WITH_NICE_THREADLEVEL=OFF \
                    -DPIKA_WITH_PRECOMPILED_HEADERS=OFF \
                    -DPIKA_WITH_THREAD_LOCAL_STORAGE=ON \
                    -DPIKA_WITH_TESTS=OFF \
                    -DPIKA_WITH_TOOLS=OFF \
                    -DPIKA_WITH_UNITY_BUILD=ON

platform powerpc {
    # For now disable multithreading until MPICH is verified to work correctly on PPC.
    # Valgrind is broken on PPC. Sanitizers are currently unsupported.
    configure.args-append \
                    -Dppc_support=ON \
                    -DPIKA_WITH_MPI_MULTITHREADED=OFF \
                    -DPIKA_WITH_VALGRIND=OFF \
                    -DPIKA_WITH_SANITIZERS=OFF

    if {${build_arch} eq "ppc64"} {
        # Remove this once Boost libcontext is fixed for ppc64:
        configure.args-append \
                    -DPIKA_WITH_BOOST_CONTEXT=OFF
    }
}

if {${os.platform} eq "darwin" && ${os.major} < 19} {
    if {[string match macports-clang* ${configure.compiler}]} {
        configure.cxxflags-append \
                    -fno-aligned-allocation \
                    -Wno-error=unused-command-line-argument
    }
}

# https://github.com/pika-org/pika/issues/584
if {${cxx_stdlib} eq "libstdc++" && [string match macports-gcc* ${configure.compiler}]} {
    set gcc_v [
        string range ${configure.compiler} [
            string length macports-gcc-
        ] end
    ]
    if {${gcc_v} < 9} {
        configure.ldflags-append -lstdc++fs
    }
}

variant jemalloc conflicts tbb description "Use jemalloc instead of system malloc" {
    depends_lib-append \
                    path:lib/pkgconfig/jemalloc.pc:jemalloc
    configure.args-append \
                    -DPIKA_WITH_MALLOC=jemalloc
}

variant tbb conflicts jemalloc description "Use oneTBB instead of system malloc" {
    depends_lib-append \
                    port:onetbb
    configure.args-append \
                    -DPIKA_WITH_MALLOC=tbbmalloc \
                    -DTBBMALLOC_ROOT=${prefix}/libexec/onetbb
}

variant tests description "Enable testing" {
    # Complete testsuite is massive. Enable only header tests by default.
    configure.args-replace \
                    -DPIKA_WITH_TESTS=OFF -DPIKA_WITH_TESTS=ON
    configure.args-append \
                    -DPIKA_WITH_ADDITIONAL_HWLOC_TESTING=ON \
                    -DPIKA_WITH_COMPILE_ONLY_TESTS=OFF \
                    -DPIKA_WITH_TESTS_BENCHMARKS=OFF \
                    -DPIKA_WITH_TESTS_EXAMPLES=OFF \
                    -DPIKA_WITH_TESTS_EXTERNAL_BUILD=OFF \
                    -DPIKA_WITH_TESTS_HEADERS=ON \
                    -DPIKA_WITH_TESTS_REGRESSIONS=OFF \
                    -DPIKA_WITH_TESTS_UNIT=OFF
    test.run        yes
    test.cmd        ctest
}

# Build system recommends against using system malloc.
if {${os.platform} eq "darwin" && ${os.major} < 10} {
    # jemalloc does not build on <= 10.5.8 atm: https://trac.macports.org/ticket/65945
    # Change this when either jemalloc or oneTBB is fixed for old systems.
    default_variants
} else {
    default_variants    +jemalloc
}
