# -*- 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           active_variants 1.1
PortGroup           github 1.0
PortGroup           meson 1.0

set gname           gtkmm
set major           3
name                ${gname}${major}
github.setup        GNOME ${gname} ${major}.24.11
revision            0

categories          x11 devel
license             LGPL-2.1+
maintainers         {devans @dbevans} {mascguy @mascguy} openmaintainer

description         C++ interface to GTK+ version ${major}.
long_description    gtkmm3 is the official C++ interface \
                    for the popular GUI library GTK+ version ${major}.
homepage            http://www.gtkmm.org

set branch          [join [lrange [split ${version} .] 0 1] .]
dist_subdir         ${gname}
distname            ${gname}-${version}

checksums           rmd160  d2a89f8a19d69c6a91450fc6e2203ab6c789f6c7 \
                    sha256  3855f6513ddcd36e9456aad55e3f69e8a6916a3318926608efc4a55241de5e53 \
                    size    2119632
github.tarball_from archive

set py_ver          3.14
set py_ver_nodot    [string map {. {}} ${py_ver}]
set port_ver_major  [lindex [split ${version} .] 0]

depends_build-append \
                    port:gtk-doc \
                    port:json-glib \
                    port:m4 \
                    port:mm-common \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  path:lib/pkgconfig/atkmm-1.6.pc:atkmm-1.6 \
                    path:lib/pkgconfig/cairomm-1.0.pc:cairomm-1.0 \
                    port:libepoxy \
                    path:lib/pkgconfig/gdk-pixbuf-2.0.pc:gdk-pixbuf2 \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    path:lib/pkgconfig/glibmm-2.4.pc:glibmm-2.4 \
                    path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                    path:lib/pkgconfig/pangomm-1.4.pc:pangomm-1.4 \
                    port:python${py_ver_nodot}

# Python only needed for scripts
depends_skip_archcheck-append \
                    python${py_ver_nodot}

# gtkmm3 > 3.16.0 requires C++11 or better
compiler.cxx_standard   2011

configure.python    ${prefix}/bin/python${py_ver}

# BTW, why?
configure.perl      /usr/bin/perl
configure.env-append \
                    PERL_PATH=${configure.perl}

configure.args-append \
                    -Dbuild-atkmm-api=true \
                    -Dbuild-demos=false \
                    -Dbuild-deprecated-api=true \
                    -Dbuild-documentation=false \
                    -Dbuild-tests=false

# GitHub tarball is incomplete:
# meson.build:262:2: ERROR: Problem encountered: Missing files in untracked/. You must enable maintainer-mode
configure.args-append \
                    -Dmaintainer-mode=true

patchfiles-append   patch-meson-build-python-path.diff

post-patch {
    reinplace -W ${worksrcpath} \
        "s|@@PYTHON@@|${configure.python}|" \
        meson.build
}

variant x11 conflicts quartz {
    require_active_variants path:lib/pkgconfig/cairomm-1.0.pc:cairomm-1.0 x11
    require_active_variants path:lib/pkgconfig/pangomm-1.4.pc:pangomm-1.4 x11
    require_active_variants path:lib/pkgconfig/gtk+-3.0.pc:gtk3 x11

    configure.args-append \
                    -Dbuild-x11-api=true
}

variant quartz conflicts x11 {
    require_active_variants path:lib/pkgconfig/cairomm-1.0.pc:cairomm-1.0 quartz
    require_active_variants path:lib/pkgconfig/pangomm-1.4.pc:pangomm-1.4 quartz
    require_active_variants path:lib/pkgconfig/gtk+-3.0.pc:gtk3 quartz

    configure.args-append \
                    -Dbuild-x11-api=false
}

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

variant tests description {Enable test support} {
    configure.args-replace \
                    -Dbuild-tests=false \
                    -Dbuild-tests=true

    test.run        yes
}
