# -*- 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 {${os.platform} eq "darwin" && ${os.major} < 11} {
    PortGroup       qmake 1.0

} else {
    PortGroup       qmake5 1.0

}

name                OpenCSG
version             1.4.2
revision            3
license             GPL-2
categories          science cad
maintainers         {dstrubbe @dstrubbe} openmaintainer
description         OpenCSG is a library that does image-based CSG rendering using OpenGL
long_description    CSG is short for Constructive Solid Geometry and denotes an approach \
                    to model complex 3D-shapes using simpler ones, i.e., two shapes can be \
                    combined by taking the union of them, by intersecting them, or by \
                    subtracting one shape of the other. The most basic shapes, which are \
                    not results of such CSG operations, are called primitives. Primitives \
                    must be solid, i.e., they must have a clearly defined interior and \
                    exterior. By construction, a CSG shape is also solid then.
homepage            https://www.opencsg.org
master_sites        ${homepage}

checksums           rmd160  d2bf9fad3691b0ddb41369d526379303121ffca6 \
                    sha256  d952ec5d3a2e46a30019c210963fcddff66813efc9c29603b72f9553adff4afb \
                    size    933135

depends_lib-append  port:glew

worksrcdir          ${distname}

post-patch {
    reinplace "s@\\.\\./glew/include@@" ${worksrcpath}/src/src.pro
}

# glew.h: error: cstdint: No such file or directory
compiler.cxx_standard   2011

configure.optflags  -O3
configure.args      -r -o Makefile opencsg.pro
build.target        sub-src-all

destroot {
    copy {*}[glob ${worksrcpath}/lib/*] ${destroot}${prefix}/lib
    copy {*}[glob ${worksrcpath}/include/*] ${destroot}${prefix}/include
    system "install_name_tool -id ${prefix}/lib/libopencsg.[lindex [split ${version} .] 0].dylib ${destroot}${prefix}/lib/libopencsg.dylib"
}

livecheck.type      regex
livecheck.url       [lindex ${master_sites} 0]
livecheck.regex     ${name}-(\[0-9.-\]+)\\.tar.gz

test.run            yes
test.target         sub-example-all
post-test {
    ui_msg "To finish the test, close the window that appears."
    system "DYLD_LIBRARY_PATH=${worksrcpath}/lib ${worksrcpath}/example/opencsgexample.app/Contents/MacOS/opencsgexample"
}
