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

github.setup        debauchee barrier 2.4.0 v
revision            0
categories          aqua net sysutils
license             GPL-2
maintainers         {@ryanakca debian.org:rak}
description         share a keyboard and mouse over the network
long_description    ${name} shares a keyboard, mouse, and clipboard over the network.\
                    It supports multiple operating systems, including macOS,\
                    Linux, FreeBSD, OpenBSD, and Windows. It is a fork of synergy.

github.tarball_from archive

checksums           rmd160  25982044cb4088ad8ccb76e336b40e493f7c8e55 \
                    sha256  20046cae7a831d9bb3740b6f04feb9bded4c794c11586a70089080e94ae2fe77 \
                    size    5572043

compiler.cxx_standard 2014

depends_build-append \
    port:ghc-filesystem \
    port:gtest \
    path:bin/pkg-config:pkgconfig

depends_lib-append \
    path:lib/libssl.dylib:openssl

# ghc-filesystem uses utimensat in its headers
legacysupport.newest_darwin_requires_legacy 16

configure.args-append \
    -DBARRIER_BUILD_INSTALLER=OFF \
    -DBARRIER_BUILD_TESTS=OFF \
    -DBARRIER_USE_EXTERNAL_GTEST=ON

# the gui requires metal
if { ${os.platform} eq "darwin" && ${os.major} < 16 } {
    configure.args-append \
        -DBARRIER_BUILD_GUI=OFF
} else {
    PortGroup   qt5 1.0
    PortGroup   app 1.0

    app.create  yes
    app.icon    dist/macos/bundle/Barrier.app/Contents/Resources/Barrier.icns
    app.retina  yes
}

if {[string match *gcc* ${configure.compiler}]} {
    # OSXScreen.mm is left as is on purpose: unlike the rest, it was orinally a .cpp file.
    post-extract {
        move ${worksrcpath}/src/lib/platform/OSXDragSimulator.mm ${worksrcpath}/src/lib/platform/OSXDragSimulator.m
        move ${worksrcpath}/src/lib/platform/OSXDragView.mm ${worksrcpath}/src/lib/platform/OSXDragView.m
        move ${worksrcpath}/src/lib/platform/OSXMediaKeySimulator.mm ${worksrcpath}/src/lib/platform/OSXMediaKeySimulator.m
        move ${worksrcpath}/src/lib/platform/OSXMediaKeySupport.mm ${worksrcpath}/src/lib/platform/OSXMediaKeySupport.m
        move ${worksrcpath}/src/lib/platform/OSXPasteboardPeeker.mm ${worksrcpath}/src/lib/platform/OSXPasteboardPeeker.m
        move ${worksrcpath}/src/lib/platform/OSXScreenSaverUtil.mm ${worksrcpath}/src/lib/platform/OSXScreenSaverUtil.m
    }

    patchfiles-append \
        0001-Add-missing-cstdint-header.patch \
        0002-libplatform-use-ObjC-flags-on-Apple.patch \
        0003-OSXScreen.mm-do-not-use-reserved-id-for-variables.patch \
        0004-basic_types.h-pull-in-cstdint-only-with-C.patch
}

post-destroot {
    xinstall -m 0644 ${worksrcpath}/doc/barrierc.1 ${destroot}${prefix}/share/man/man1/barrierc.1
    xinstall -m 0644 ${worksrcpath}/doc/barriers.1 ${destroot}${prefix}/share/man/man1/barriers.1
    xinstall -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 0644 -W ${worksrcpath}/doc/ \
            barrier.conf.example \
            barrier.conf.example-advanced \
            barrier.conf.example-basic \
            ${destroot}${prefix}/share/doc/${name}
}
