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

github.setup            oxen-io oxen-mq 1.2.17 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from     tarball
name                    oxenmq
revision                0
categories              devel net
maintainers             nomaintainer
license                 BSD
description             High-level zeromq-based message passing for network-based projects
long_description        {*}${description}
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
}

depends_build-append    path:bin/pkg-config:pkgconfig

depends_lib-append      port:libsodium \
                        port:oxenc \
                        path:lib/libzmq.dylib:zmq

compiler.cxx_standard   2017
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

# 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
