# -*- 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                    Tencent rapidjson ebd87cb468fb4cb060b37e579718c4a4125416c1
version                         20241202
revision                        0
name                            rapidjson-devel

checksums                       rmd160  723b2fc13339aa594c24ee8f41a6d23ceedadb99 \
                                sha256  ff469e4815b534c9b5695eafe41d8047950082c74dc6171aa0622353f31b1d8d \
                                size    1116577
github.tarball_from             archive
license                         MIT
categories                      devel
if {![variant_isset examples]} {
    platforms                   any
    supported_archs             noarch
}

# original by {@Lord-Kamina gmail.com:g.litenstein}
maintainers                     nomaintainer

conflicts                       rapidjson

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               0001-CMakeLists-fix-optflags-for-ppc.patch \
                                0002-Wno-sign-conversion-Wno-sign-compare-with-GCC.patch

compiler.cxx_standard           2011

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

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
        # Otherwise destroot code fails:
        move    ${cmake.build_dir}/bin/archivertest ${cmake.build_dir}/bin/archiver

        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} {
    # https://github.com/Tencent/rapidjson/issues/2118
    compiler.cxx_standard       2014
    patchfiles-append           patch-fix-cxx-standard.diff
    depends_build-append        port:gtest
    configure.args-append       -DRAPIDJSON_BUILD_THIRDPARTY_GTEST=ON \
                                -DGTEST_SOURCE_DIR=${prefix}/src/googletest
    configure.args-replace      -DRAPIDJSON_BUILD_TESTS=OFF -DRAPIDJSON_BUILD_TESTS=ON
    test.run                    yes
}
