# -*- 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        contour-terminal libunicode 0.9.3 v
revision            0
categories          devel textproc
license             Apache-2
maintainers         {@barracuda156 macos-powerpc.org:barracuda} openmaintainer
description         Modern C++20 Unicode Library
long_description    {*}${description}
checksums           rmd160  4abf5754343e0f431318bc9198a716c76d8ce2f5 \
                    sha256  78b715bc2d929530bc89e47c1c6772b72f511e1831b14e7d6d92cceb62592920 \
                    size    146384
github.tarball_from archive

set py_ver          3.14
set py_ver_nodot    [string map {. {}} ${py_ver}]

# Only needed if building with tests enabled:
depends_build-append \
                    port:python${py_ver_nodot}

compiler.cxx_standard   2020

# C++20 is the default here, but control it explicitly.
configure.args-append \
                    -DCMAKE_CXX_STANDARD=20 \
                    -DLIBUNICODE_BENCHMARK=OFF \
                    -DLIBUNICODE_BUILD_STATIC=OFF \
                    -DLIBUNICODE_EXAMPLES=OFF \
                    -DLIBUNICODE_SIMD_IMPLEMENTATION="std" \
                    -DLIBUNICODE_TESTING=OFF \
                    -DLIBUNICODE_TOOLS=ON \
                    -DPython3_EXECUTABLE=${prefix}/bin/python${py_ver}

patch.pre_args-replace  -p0 -p1

if {${os.platform} eq "darwin" && ${os.major} < 22 && ${configure.cxx_stdlib} eq "libc++"} {
    patchfiles-append   libunicode-fmt-support.patch

    set fmt_v           12
    cmake.prefix_path-append \
                        ${prefix}/lib/libfmt${fmt_v}/cmake
    depends_lib-append  port:libfmt${fmt_v}
    configure.args-append \
                        -DLIBUNICODE_USE_FMT=ON
}

# This is needed regardless of testing:
# dyld: Library not loaded: @rpath/libunicode_loader.0.6.dylib
configure.pre_args-replace \
                    -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON \
                    -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=OFF

# On 10.6.8 powerpc:
# 100% tests passed, 0 tests failed out of 1
variant tests description "Build tests" {
    depends_build-append \
                    port:catch2
    configure.args-replace \
                    -DLIBUNICODE_TESTING=OFF -DLIBUNICODE_TESTING=ON
    test.run        yes
}
