# -*- 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
PortGroup               openssl 1.0

# At least clock_gettime in mongoose
legacysupport.newest_darwin_requires_legacy 15

github.setup            xfangfang wiliwili 1.5.2 v
revision                0
categories              multimedia www
maintainers             {@barracuda156 macos-powerpc.org:barracuda} openmaintainer
license                 GPL-3
description             Cross-platform client for bilibili
long_description        {*}${description} B站.
homepage                https://www.xfangfang.cn/${name}

checksums               rmd160  a7079b438530c51d8cec930835b85105ffbcfc91 \
                        sha256  885db32627381dd2641c69c0baee0f716a3f8ae39ce9f4abb007f7e615de4eab \
                        size    16102983
github.tarball_from     archive
github.livecheck.branch yoga

fetch.type              git

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

# Discussion: https://github.com/xfangfang/wiliwili/issues/570

# wiliwili
patchfiles-append       0001-Support-external-lunasvg.patch \
                        0002-qr_image.hpp-add-a-missing-header.patch \
                        0003-string_helper.cpp-fix-compilation-error.patch \
                        0004-Allow-customized-builds-on-macOS.patch

# borealis
patchfiles-append       0005-Allow-not-to-force-build-settings-for-macOS.patch \
                        0006-Support-building-on-10.7.patch

set libfmt_v            11
cmake.module_path-append \
                        ${prefix}/lib/libfmt${libfmt_v}/cmake

depends_build-append    path:bin/pkg-config:pkgconfig
depends_lib-append      port:cpr \
                        port:curl \
                        port:libfmt${libfmt_v} \
                        port:libsdl2 \
                        port:lunasvg \
                        path:lib/libmpv.dylib:mpv \
                        port:pystring \
                        port:tinyxml2 \
                        port:webp \
                        port:zlib

compiler.cxx_standard   2017
configure.ccache        no

# USE_SHARED_LIB controls whether external deps are used; however, we keep options
# explicit for convenience.
# mongoose is available as a port, but does not install a lib, and if that is installed,
# it is not found by CMake. No big deal to build a bundled one.
# USE_BOOST_FILESYSTEM=ON will be needed for legacy systems relying on old Apple libc++.
# Building with external tweeny is broken: https://github.com/xfangfang/borealis/issues/111
configure.args-append   -DAPP_PLATFORM_CUSTOM_LIBS=ON \
                        -DBUNDLE_MACOS_APP=OFF \
                        -DCUSTOM_RESOURCES_DIR=OFF \
                        -DDISABLE_OPENCC=ON \
                        -DDISABLE_WEBP=OFF \
                        -DMAC_CUSTOM_BUILD=ON \
                        -DMAC_DOWNLOAD_DYLIB=OFF \
                        -DPLATFORM_DESKTOP=ON \
                        -DUSE_BOOST_FILESYSTEM=OFF \
                        -DUSE_GL2=ON \
                        -DUSE_SDL2=ON \
                        -DUSE_SHARED_LIB=ON \
                        -DUSE_SYSTEM_CPR=ON \
                        -DUSE_SYSTEM_CURL=ON \
                        -DUSE_SYSTEM_FMT=ON \
                        -DUSE_SYSTEM_GLFW=OFF \
                        -DUSE_SYSTEM_LUNASVG=ON \
                        -DUSE_SYSTEM_MONGOOSE=OFF \
                        -DUSE_SYSTEM_OPENCC=OFF \
                        -DUSE_SYSTEM_PYSTRING=ON \
                        -DUSE_SYSTEM_QRCODEGEN=OFF \
                        -DUSE_SYSTEM_SDL2=ON \
                        -DUSE_SYSTEM_TINYXML2=ON \
                        -DUSE_SYSTEM_TWEENY=OFF

# The build does not pick needed flags:
configure.cppflags-append \
                        -I${prefix}/include/libfmt${libfmt_v} \
                        -I${prefix}/include/lunasvg
configure.ldflags-append \
                        -L${prefix}/lib/libfmt${libfmt_v}

platform darwin {
    if {${os.major} < 17 && ${configure.cxx_stdlib} eq "libc++"} {
        PortGroup       boost 1.0

        boost.version   1.81

        configure.args-replace \
                        -DUSE_BOOST_FILESYSTEM=OFF -DUSE_BOOST_FILESYSTEM=ON
    }
}

variant opencc description "Build with OpenCC support" {
    depends_lib-append  port:opencc
    configure.args-replace \
                        -DDISABLE_OPENCC=ON -DDISABLE_OPENCC=OFF \
                        -DUSE_SYSTEM_OPENCC=OFF -DUSE_SYSTEM_OPENCC=ON
}

destroot {
    copy ${cmake.build_dir}/${name} ${destroot}${prefix}/bin/
}
