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

if {[variant_isset qt5]} {
    PortGroup                   qmake5 1.0
    PortGroup                   muniversal 1.0
} else {
    PortGroup                   qmake 1.0
}

name                            libQGLViewer
version                         2.6.4
revision                        1
platforms                       darwin
maintainers                     {raphael @raphael-st} openmaintainer
license                         {GPL-2+ Commercial}
categories                      graphics
description                     A C++ library based on Qt that eases the creation of OpenGL \
                                3D viewers
homepage                        http://www.libqglviewer.com/
long_description                libQGLViewer is a C++ library based on Qt that eases the \
                                creation of OpenGL 3D viewers. It provides some of the typical \
                                3D viewer functionalities, such as the possibility to move the \
                                camera using the mouse, which lacks in most of the other APIs. \
                                Other features include mouse manipulated frames, interpolated \
                                keyFrames, object selection, stereo display, screenshot saving \
                                and much more. It can be used by OpenGL beginners as well as \
                                to create complex applications, being fully customizable and \
                                easy to extend.

master_sites                    ${homepage}src/

checksums                       rmd160  242c5d3ac42ac878cc1ad0b5b7eaa5f434ef9e89 \
                                sha256  53daefd7981a3ff7719ee55c368226807791d916ed988dde0aa0eac89686389d

patchfiles                      patch-QGLViewer.pro.diff \
                                patch-examples.pri.diff  \
                                patch-designerPlugin.pro.diff

post-patch {
    reinplace "s|@@QT_PLUGINS_DIR@@|${qt_plugins_dir}|g" ${worksrcpath}/designerPlugin/designerPlugin.pro
}

if {[variant_isset qt4] && (!${universal_possible} || ![variant_isset universal])} {
    configure.pre_args-append   "CONFIG+=\"${qt_arch_types}\""
}

# prevent the examples from linking with an already installed version of libQGLViewer (#41382)
configure.cppflags-delete -I${prefix}/include
configure.ldflags-delete -L${prefix}/lib

# clear all arch-oriented flags since they mess up LDFLAGS in Makefiles (#41359)
configure.ld_archflags
configure.cc_archflags
configure.cxx_archflags
configure.universal_ldflags
configure.universal_cflags
configure.universal_cxxflags
configure.universal_cppflags
configure.march
configure.mtune

configure.pre_args-append       DOC_DIR=${prefix}/share/doc/${name}
if {[variant_isset qt4]} {
    configure.post_args-append  -after QMAKE_POST_LINK=\"\"
} else {
    configure.args-append       CONFIG+=absolute_library_soname
}

use_parallel_build              no

if {!${universal_possible} || ![variant_isset universal] || ![variant_isset qt5]} {
    post-destroot {
        system -W ${worksrcpath}/examples "make clean"
        copy ${worksrcpath}/examples ${destroot}${applications_dir}/libQGLViewer\ Examples
        xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}
        xinstall -m 644 -W ${worksrcpath} \
            CHANGELOG \
            GPL_EXCEPTION \
            LICENCE \
            README \
            ${destroot}${prefix}/share/doc/${name}
    }
} else {
    merger-post-destroot {
        foreach arch ${universal_archs_supported} {
            system -W ${worksrcpath}-${arch}/examples "make clean"
            copy ${worksrcpath}-${arch}/examples ${destroot}-${arch}${applications_dir}/libQGLViewer\ Examples

            xinstall -m 755 -d ${destroot}-${arch}${prefix}/share/doc/${name}
            xinstall -m 644 -W ${worksrcpath}-${arch} \
                CHANGELOG \
                GPL_EXCEPTION \
                LICENCE \
                README \
                ${destroot}-${arch}${prefix}/share/doc/${name}
        }
    }
}

variant qt4 description {build with Qt 4} conflicts qt5 {}

variant qt5 description {build with Qt 5} conflicts qt4 {
    depends_lib-append port:qt5-qttools
}

if {![variant_isset qt4] && ![variant_isset qt5]} {
    default_variants-append +qt4
}

if {![variant_isset qt4] && ![variant_isset qt5]} {
    ui_error "You must select a qt variant to use."
    return -code error "No qt variant selected."
}

livecheck.type                  regex
livecheck.regex                 "Version (\\d+(?:\\.\\d+)*)"
