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

# https://trac.macports.org/ticket/67411
legacysupport.newest_darwin_requires_legacy 16
legacysupport.use_mp_libcxx yes

github.setup        yhirose cpp-peglib 1.9.1 v
revision            0
categories          devel
# Do not set is as noarch until this issue is fixed:
# https://trac.macports.org/ticket/69317
# platforms           any
# supported_archs     noarch
license             MIT
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         A single file C++ header-only PEG (Parsing Expression Grammars) library
long_description    {*}${description}
checksums           rmd160  374020009ffed7bc719fec8bdbf1499849b4a521 \
                    sha256  f57aa0f14372cbb772af29e3a4549a8033ea07eb25c39949cba6178e0e2ba9cc \
                    size    228336
github.tarball_from archive

# The port needs Gtest for building tests, however linking to external Gtest fails.
# It uses git to fetch needed branch of Gtest.
platform darwin {
    if {${os.major} < 13} {
        # Lion+ (with Xcode 4.1+) have git; earlier need to bring their own.
        # On 10.8.5 git fetch fails with ssl error.
        depends_build-append    port:git
        git.cmd                 ${prefix}/bin/git
    }
}

compiler.cxx_standard 2017
compiler.blacklist-append \
                    {clang < 902}

configure.args-append \
                    -DBUILD_TESTS=ON \
                    -DTHREADS_PREFER_PTHREAD_FLAG=ON

# We do not want a conflict with Gtest port, so implement a manual destroot.
destroot {
    copy ${worksrcpath}/peglib.h ${destroot}${prefix}/include/
    xinstall -d ${destroot}${prefix}/share/${name}
    fs-traverse f ${worksrcpath}/docs {
        if {[file exists ${f}] && [file isfile ${f}]} {
            copy ${f} ${destroot}${prefix}/share/${name}/
        }
    }
}

test.run            yes
test.cmd            ctest
