# -*- 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-encoding 1.0.10 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from     tarball
name                    oxenc
revision                0
categories              net crypto
maintainers             {@barracuda156 gmail.com:vital.had} openmaintainer
license                 LGPL-3
platforms               any
supported_archs         noarch
description             Base 16/32/64 and bittorrent encoding/decoding header-only library
long_description        {*}${description}

# Using Macports version of Catch2 fails.
fetch.type              git

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

patchfiles-append       patch-CMakeLists.diff

# Review this upon a reply from upstream: https://github.com/oxen-io/oxen-encoding/issues/24
# Possibly, an ugly fallback in variant.h can be dropped for builds with GCC.

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

compiler.cxx_standard   2017

configure.args-append   -DOXENC_BUILD_DOCS:BOOL=OFF \
                        -DOXENC_BUILD_TESTS:BOOL=ON \
                        -DOXENC_INSTALL:BOOL=ON

# Build auto-detects ccache if it is installed and attempts to write
# to CCACHE_DIR, which is not allowed if configure.ccache=off.
# Set CCACHE_DIR to the build directory instead.
if {![option configure.ccache]} {
    configure.env-append   CCACHE_DIR=${workpath}/.ccache
    build.env-append       CCACHE_DIR=${workpath}/.ccache
    destroot.env-append    CCACHE_DIR=${workpath}/.ccache
}

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