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

epoch                   1
github.setup            nextcloud desktop 3.5.2 v
revision                0
github.tarball_from     archive
# Handle stealth update; remove with next version update
dist_subdir             ${name}/${version}_1
checksums               rmd160 9c1da0dc2febfd5e4d14a7eb01954610561fc92a \
                        sha256 0c467310e1a1b32593446584c6a5d7a931b7e2da3d1721dac8b0ac53cc493088 \
                        size   15433543

name                    nextcloud-client
categories              www aqua
maintainers             nomaintainer
license                 GPL-2+
description             Desktop Syncing Client for Nextcloud
long_description \
    The Nextcloud Desktop Client is a tool to synchronize files from Nextcloud \
    server with your computer.
homepage                https://nextcloud.com/

use_xcode               yes
compiler.cxx_standard   2014

depends_lib-append      port:sqlite3 port:zlib port:qtkeychain-qt5

depends_build-append    path:lib/pkgconfig/librsvg-2.0.pc:librsvg

qt5.min_version         5.12
qt5.depends_component   qtmacextras qtquickcontrols2 qtwebsockets
qt5.depends_build_component \
                        qttools

patchfiles              patch-use-system-sqlite.diff \
                        patch-add-xcodeflags.diff \
                        patch-no-deployqt.diff \
                        patch-remove-inkscape.diff

# Fix builds pre macOS 11 - may be removed in future release
# Note that upstream patch doesn't work as-is; required updating to use preprocessor block, rather than runtime
# https://github.com/nextcloud/desktop/pull/4563/commits/4bdfe5927051741584b86ba6c45054f0679357d4
patchfiles-append       patch-fix-build-pre-macos-11.diff

cmake.install_prefix    ${applications_dir}

configure.args-append   -DCMAKE_INSTALL_NAME_DIR=${applications_dir}/Nextcloud.app/Contents/MacOS \
                        -DXCODEFLAGS="-IDECustomDerivedDataLocation=${workpath}/DerivedData" \
                        -DBUILD_UPDATER=OFF \
                        -DWITH_CRASHREPORTER=OFF \
                        -DBUILD_OWNCLOUD_OSX_BUNDLE=ON \
                        -DSVG_CONVERTER_DIR=${prefix}/bin

if {${os.major} < 13} {
    # Finder extension does not compile on 10.8
    configure.pre_args-append   -DBUILD_SHELL_INTEGRATION=OFF
}

post-destroot {
    ln -s ${applications_dir}/Nextcloud.app/Contents/MacOS/nextcloudcmd \
        ${destroot}${prefix}/bin/nextcloudcmd
}
