# -*- 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
PortGroup           conflicts_build 1.0
PortGroup           wxWidgets 1.0

name                h3dapi
version             2.4.0
revision            5
categories          graphics
platforms           darwin
maintainers         {@SenseGraphics sensegraphics.com:support}
license             GPL-2+

description         Headers and libraries for H3DAPI development.

long_description    H3DAPI provides is a scenegraph based API with one \
                    unified scene graph to handle both graphics and haptics\
                    based on the X3D standard.

subport             h3dload {
    revision            1
    description         Command line X3D browser based on H3DAPI.
    long_description    X3D browser with custom extensions for haptics and medical simulation.
}
subport             h3dviewer {
    revision            1
    description         X3D browser based on H3DAPI.
    long_description    X3D browser with custom extensions for haptics and medical simulation.
}

homepage            http://www.h3dapi.org
master_sites        ftp://www.h3dapi.org/pub/releases/source/

checksums           rmd160  26e7ebf8dc1d315d8aa817c0db6ec6eefb293e36 \
                    sha256  5f3d9262f125324c8bc52f099214ce2a78b58f7e1ba15b16ff97cfaf40a8f853 \
                    size    29822042

patchfiles          patch-FindAudiofile-PreventFramework.diff

depends_lib         port:audiofile \
                    port:bzip2 \
                    port:curl \
                    port:fontconfig \
                    port:freeglut \
                    port:freetype \
                    port:ftgl \
                    port:glew \
                    port:hapi \
                    port:libvorbis \
                    port:openexr \
                    port:python27 \
                    port:spidermonkey \
                    port:xercesc

if {${subport} eq ${name}} {

    depends_lib     port:hapi \
                    port:glew \
                    port:xercesc3 \
                    port:ftgl \
                    port:libvorbis \
                    port:audiofile \
                    port:spidermonkey \
                    port:fontconfig

    configure.post_args \
                    ${worksrcpath}/build

    compiler.cxx_standard  2011
    configure.cxxflags-append -std=gnu++11

    configure.args  -DGENERATE_H3DAPI_loader_PROJECTS:BOOL=OFF \
                    -DGENERATE_H3DLoad_PROJECTS:BOOL=OFF \
                    -DGENERATE_H3DViewer_PROJECTS:BOOL=OFF

} elseif {${subport} eq "h3dload"} {

    depends_lib     port:h3dapi

    configure.post_args \
                    ${worksrcpath}/H3DLoad/build

} elseif {${subport} eq "h3dviewer"} {

    wxWidgets.use   wxWidgets-3.0

    depends_lib     port:h3dapi \
                    port:h3dui \
                    port:h3dmedx3d \
                    port:h3dphysics \
                    port:${wxWidgets.port}

    configure.post_args \
                    ${worksrcpath}/H3DViewer/build

    configure.args  -DOSX_BUNDLE_INSTALL_DESTINATION=${applications_dir} \
                    -DCMAKE_PREFIX_PATH=${prefix} \
                    -DwxWidgets_CONFIG_EXECUTABLE=${wxWidgets.wxconfig}

    post-destroot {
        file attributes ${destroot}${applications_dir}/H3DViewer.app/Contents/Resources/H3DViewer.icns -permissions a+r
        # TODO: this seems a bit weird (test if symlinks work as well)
        set  plugin_dir ${destroot}${applications_dir}/H3DViewer.app/Contents/Resources/Plugins
        xinstall -d ${plugin_dir}
        foreach file { medx3d ui physics } {
            xinstall ${prefix}/lib/libh3d${file}.dylib ${plugin_dir}
        }
    }
}

conflicts_build-append  openexr
configure.args-append   -DOpenEXR_INCLUDE_DIR=${prefix}/libexec/openexr2/include \
                        -DOpenEXR_Half_LIBRARY_RELEASE=${prefix}/libexec/openexr2/lib/libHalf.dylib \
                        -DOpenEXR_Iex_LIBRARY_RELEASE=${prefix}/libexec/openexr2/lib/libIex.dylib \
                        -DOpenEXR_IlmImf_LIBRARY_RELEASE=${prefix}/libexec/openexr2/lib/libIlmImf.dylib \
                        -DOpenEXR_IlmThread_LIBRARY_RELEASE=${prefix}/libexec/openexr2/lib/libIlmThread.dylib \
                        -DOpenEXR_Imath_LIBRARY_RELEASE=${prefix}/libexec/openexr2/lib/libImath.dylib

livecheck.type      regex
livecheck.url       ${master_sites}/
livecheck.regex     h3dapi-(\[0-9.\]+)${extract.suffix}
