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

name                oofcanvas
version             1.1.2
revision            0

license             public-domain
categories          graphics
maintainers         {@snarkhunter nist.gov:stephen.langer} \
                    nist.gov:oof_manager openmaintainer

description         C++ library that does some of what libgnomecanvas used to do
long_description    OOFCanvas is a replacement for libgnomecanvas, designed \
                    for use in OOF2, but hopefully useful elsewhere. OOFCanvas \
                    is based on Cairo and, unlike libgnomecanvas, is compatible \
                    with gtk3. The canvas is a drawing area that can display \
                    a variety of shapes, including text. It can be scrolled, \
                    zoomed, and printed. Items drawn on the canvas can be \
                    selected with the mouse. Note that OOFCanvas is not \
                    a drop-in replacement for libgnomecanvas.  It's also not \
                    a full-fledged gtk widget. It's a set of classes that does \
                    some of what libgnomecanvas did and uses gtk.

homepage            https://www.ctcms.nist.gov/oof/oofcanvas
master_sites        ${homepage}/source

checksums           rmd160 cfaa3fa935ac55183ee02dd06dffe60e13c7bc36 \
                    sha256 6d4faef05ab89f7644deecb7c7bef65d874852227b1c0818bbc0967bfe7f4ed5 \
                    size 100083

compiler.cxx_standard 2011
cmake.build_type    Release

livecheck.type      regex
livecheck.url       ${homepage}
livecheck.regex     "source/oofcanvas-(\\d+(?:\\.\\d+)*).tar.gz"

# clang 503.0.40 provided by Xcode 5.1.1 supports C++11 but apparently not <type_traits>
# fatal error: 'type_traits' file not found
# #include <type_traits>
compiler.blacklist-append {clang < 600.0.57}

depends_build-append \
                    path:bin/cmake:cmake \
                    path:bin/pkg-config:pkgconfig \
                    port:swig-python

depends_lib-append  port:cairomm \
                    path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \

configure.args-append \
                    -DOOFCANVAS_SWIG_VERSION=4.1

set python_versions {312 311 310 39}

foreach v ${python_versions} {
    set minor [string range ${v} 1 end]
    # This variant conflicts with all other python variants
    set conflictversions [lsearch -all -inline -not ${python_versions} $v]
    set conflictswith {}
    foreach cv ${conflictversions} {
        lappend conflictswith python$cv
    }
    variant python${v} description "Build the API for Python 3.${minor}" \
        conflicts {*}$conflictswith \
        [ subst {
            depends_lib-append \
                port:py${v}-gobject3 \
                port:python${v}
            configure.args-append \
                -DOOFCANVAS_PYTHON_API=Python3 \
                -DOOFCANVAS_PYTHON3_VERSION=3.${minor} \
                -DOOFCANVAS_SYSTEM_INSTALL=ON \
                -DPython_EXECUTABLE=${prefix}/bin/python3.${minor} \
                -DPYGOBJECT_INCLUDE_DIRS=${frameworks_dir}/Python.framework/Versions/3.${minor}/include/python3.${minor}/pygobject/pygobject-3.0
        }]
}

variant magick description {Add support for ImageMagick images} {
    configure.args-append   -DOOFCANVAS_USE_IMAGEMAGICK=ON
    depends_lib-append      port:ImageMagick
}

variant numpy description {Add support for NumPy images (at your own risk)} {
    configure.args-append   -DOOFCANVAS_USE_NUMPY=ON
}

# python311 is the default variant if no other python variant is set
set vactive 0
foreach v ${python_versions} {
    if [variant_isset python$v] {
        set vactive 1
    }
}
if { !$vactive } {
    default_variants +magick +python311
} else {
    default_variants +magick
}

