# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8::et:sw=4:ts=4:sts=4

PortSystem              1.0
PortGroup               legacysupport 1.1
PortGroup               github 1.0
PortGroup               cmake  1.1
PortGroup               app    1.1
PortGroup               active_variants 1.1

github.setup            giuspen cherrytree 1.6.2 v
revision                0

categories              editors
license                 GPL-3+
maintainers             {mascguy @mascguy} openmaintainer

description             Hierarchical Note Taking
long_description        A Hierarchical Note Taking Application, featuring Rich Text\
                        and Syntax Highlighting

github.tarball_from     releases
use_xz                  yes
distname                ${name}_${version}

checksums               rmd160  ced0180794c755c1ab67e31e318ace25a17a5c23 \
                        sha256  28c89a0b2512961e9d9393a5b8f7778f99331583c9bdbe682c4897b853727158 \
                        size    3583244

# Enable use of 'macports-libcxx' for macOS 10.12 and earlier, as port uses
# libcxx features normally only available on 10.13 and later.
legacysupport.use_mp_libcxx \
                        yes

set port_libfmt         libfmt9
configure.pkg_config_path-append \
                        ${prefix}/lib/${port_libfmt}/pkgconfig
cmake.module_path-append \
                        ${prefix}/lib/${port_libfmt}/cmake
configure.ldflags-append \
                        -L${prefix}/lib/${port_libfmt}

compiler.cxx_standard   2017

patchfiles-append       patch-cherrytree-all-apple-is-not-homebrew-for-goodness-sake.diff

# By default, project enables significant warnings, via Wall/Wextra. Disable that behavior.
patchfiles-append       patch-drop-wall.diff

depends_build-append    path:bin/pkg-config:pkgconfig

depends_build-append    port:python313
configure.args-append   -DPYTHON_EXEC=${prefix}/bin/python3.13

depends_lib-append      port:adwaita-icon-theme \
                        port:atk \
                        port:atkmm \
                        path:lib/pkgconfig/cairo.pc:cairo \
                        port:cairomm \
                        port:curl \
                        port:enchant2 \
                        path:lib/pkgconfig/gdk-pixbuf-2.0.pc:gdk-pixbuf2 \
                        port:gettext \
                        path:lib/pkgconfig/glib-2.0.pc:glib2 \
                        path:lib/pkgconfig/glibmm-2.68.pc:glibmm \
                        port:gspell \
                        path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                        port:gtkmm3 \
                        port:gtksourceview4 \
                        port:gtksourceviewmm3 \
                        path:lib/pkgconfig/harfbuzz.pc:harfbuzz \
                        port:${port_libfmt} \
                        port:libsigcxx2 \
                        port:libxmlxx2 \
                        port:libxml2 \
                        path:lib/pkgconfig/pango.pc:pango \
                        path:lib/pkgconfig/pangomm-2.48.pc:pangomm \
                        port:sqlite3 \
                        port:spdlog \
                        port:uchardet

configure.args-append   -DBUILD_TESTING=OFF
configure.args-append   -DUSE_VTE=OFF

if {${os.platform} eq "darwin" && ${os.major} < 13} {
    # uses '-k' option to gzip which is not supported until 10.9
    depends_build-append  port:gzip
}

# Clear optflags; controlled by project, via cmake build type
configure.optflags

if {[variant_isset debug]} {
    cmake.build_type    Debug
} else {
    cmake.build_type    Release
}

app.name                CherryTree
app.icon                ${worksrcpath}/icons/cherrytree.ico
app.use_launch_script   yes
app.retina              yes

variant x11 conflicts quartz {
   require_active_variants gtk3 x11 quartz

   notes-append    "This is ${name} +x11. You will need an X11 server installed, either\
                    xorg-server from MacPorts or XQuartz, to view this application. If you\
                    prefer a macOS-native quartz version, please install ${name} +quartz instead."
}

variant quartz conflicts x11 {
   require_active_variants gtk3 quartz x11
}

if {![variant_isset quartz]} {
    default_variants-append +x11
}
