# -*- 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                       github 1.0
PortGroup                       cmake 1.1

github.setup                    Tencent rapidjson 1.1.0 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from             tarball
revision                        2

checksums                       rmd160  34724d9db66afadc3273f26d77efae8cb0322980 \
                                sha256  f3987b47054748cf099a22001d0cbd6963aaccbdce789e800558822c1b2d8356 \
                                size    1019591

license                         MIT
categories                      devel
if {![variant_isset examples]} {
platforms                       any
supported_archs                 noarch
}

maintainers                     {mcalhoun @MarcusCalhoun-Lopez} openmaintainer

conflicts                       rapidjson-devel

description                     A fast JSON parser/generator for C++ with both SAX/DOM style API.
long_description                RapidJSON is a fast, unicode-friendly, self-contained \
                                and header-only library without any dependencies for parsing JSON.

homepage                        https://rapidjson.org/

patchfiles-append               patch-flags.diff \
                                remove-assignment-operator.patch \
                                patch-test-CmakeLists.txt.diff \
                                patch-access_fix.diff \
                                patch-base.diff

compiler.cxx_standard           2011

configure.args-append           -DRAPIDJSON_BUILD_DOC=OFF \
                                -DRAPIDJSON_BUILD_EXAMPLES=OFF \
                                -DRAPIDJSON_BUILD_TESTS=OFF \
                                -DRAPIDJSON_HAS_STDSTRING=ON

variant docs description {Build documentation} {
    depends_build-append        path:bin/doxygen:doxygen \
                                path:bin/dot:graphviz
    configure.args-delete       -DRAPIDJSON_BUILD_DOC=OFF
}

variant examples description {Build examples} {
    configure.args-delete       -DRAPIDJSON_BUILD_EXAMPLES=OFF
}
post-destroot {
    if {[variant_isset examples]} {
        xinstall -d -m 0755 ${destroot}${prefix}/share/examples
        move    ${destroot}${prefix}/share/doc/RapidJSON/examples \
                ${destroot}${prefix}/share/examples/RapidJSON

        foreach example [glob -tails -directory ${cmake.build_dir}/bin *] {
            xinstall -m 0755 \
                ${cmake.build_dir}/bin/${example} \
                ${destroot}${prefix}/share/examples/RapidJSON/${example}/
        }
    } else {
        delete  ${destroot}${prefix}/share/doc/RapidJSON/examples
    }
}

variant tests description {Build and run unit tests} {
    depends_test-append         port:gtest
    configure.args-delete       -DRAPIDJSON_BUILD_TESTS=OFF
    test.run                    yes

    # gtest requires C++14
    compiler.cxx_standard       2014
    configure.args-append       -DCMAKE_CXX_STANDARD=14
}
