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

# Development seems to have moved to https://github.com/session-foundation/liboxenmq
github.setup            oxen-io oxen-mq 1.3.0 v
name                    oxenmq
revision                1
categories              devel net
maintainers             {@barracuda156 macos-powerpc.org:barracuda} openmaintainer
license                 BSD
description             High-level zeromq-based message passing for network-based projects
long_description        {*}${description}
# checksums               rmd160  447e981be1cbfacef6e355c5496a03caef2d0736 \
#                         sha256  1f19b64ebd90d5d5e339286783072e2e1421f67cb2936dc29979d8e997b5db30 \
#                         size    106349
# github.tarball_from     archive

# https://github.com/oxen-io/oxen-mq/issues/97
fetch.type              git

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

patchfiles-append       patch-CMakeLists.diff

post-patch {
    reinplace "s,@MACOS@,${macosx_deployment_target}," ${worksrcpath}/CMakeLists.txt
}

# Match spdlog
set port_libfmt         libfmt12
cmake.prefix_path-append \
                        ${prefix}/lib/${port_libfmt}/cmake

depends_build-append    port:cppzmq \
                        path:bin/pkg-config:pkgconfig

depends_lib-append      port:${port_libfmt} \
                        port:libsodium \
                        port:oxen-logging \
                        port:oxenc \
                        port:spdlog \
                        path:lib/libzmq.dylib:zmq

compiler.cxx_standard   2020
compiler.thread_local_storage yes

configure.args-append   -DBUILD_SHARED_LIBS:BOOL=ON \
                        -DOXENMQ_BUILD_TESTS:BOOL=ON \
                        -DOXENMQ_INSTALL:BOOL=ON \
                        -DOXENMQ_INSTALL_CPPZMQ:BOOL=OFF

if {${os.platform} ne "linux"} {
    configure.args-append \
                        -DOXENMQ_USE_EPOLL:BOOL=OFF
}

# https://github.com/oxen-io/oxen-mq/issues/86
if {[string match *gcc* ${configure.compiler}] \
    && ${configure.build_arch} in [list arm i386 ppc]} {
    # ___atomic_fetch_add_8
    configure.ldflags-append \
                        -latomic
}

test.run                yes
test.cmd                ${cmake.build_dir}/tests/tests
test.target
