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

github.setup        embree embree 3.13.5 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            1
categories          graphics
license             Apache-2
maintainers         @jasonliu-- openmaintainer
homepage            https://www.embree.org
description         collection of high-performance ray tracing kernels
long_description    Embree is a ${description}, developed at Intel. It \
                    contains algorithms optimized for incoherent \
                    workloads (e.g. Monte Carlo ray tracing \
                    algorithms) and coherent workloads (e.g. primary \
                    visibility and hard shadow rays). It also supports \
                    dynamic scenes by implementing high-performance \
                    two-level spatial index structure construction \
                    algorithms.

checksums           rmd160  659c93eae9724d73df9ef65b438eecd7516613d6 \
                    sha256  7a03f48f194b66a98e8eef61d56674fc08433b46b97aaecbb2cd5b05b9d77512 \
                    size    13739276

depends_build-append \
                    port:ispc
depends_lib-append  port:tbb \
                    port:glfw \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    port:libpng \
                    port:openimageio

compiler.cxx_standard 2011

post-patch {
    # Put tutorials in ${prefix}/share/embree instead of ${prefix}/bin
    reinplace "/INCLUDE.GNUInstallDirs/a\\
SET(CMAKE_INSTALL_BINDIR \${CMAKE_INSTALL_PREFIX}/share/embree\${EMBREE_VERSION_MAJOR})\\
" \
        ${worksrcpath}/common/cmake/package.cmake
}

configure.args-append   -DEMBREE_TUTORIALS=OFF

# NOTE it may picks OneTBB via CMake config, disable it until port is migrated
configure.args-append   -DTBB_FIND_PACKAGE_OPTION=NO_DEFAULT_PATH \
                        -DTBB_ROOT=${prefix}/libexec/tbb

post-destroot {
    if {[file exists ${destroot}${prefix}/share/uninstall.command]} {
        delete ${destroot}${prefix}/share/uninstall.command
    }
}

variant static description {Build Embree as a static library} {
    # Patch CMake scripts to produce both static and dynamic libraries
    # when using the +static variant. (By default, Embree's CMake
    # scripts can be set to output either dynamic or static libraries,
    # but not both at the same time.)
    patchfiles-append       patch-static-lib.diff

    configure.args-append   -DEMBREE_STATIC_LIB=ON
}

variant tutorials description {Build tutorials} {
    configure.args-replace  -DEMBREE_TUTORIALS=OFF -DEMBREE_TUTORIALS=ON
}

variant ray_mask description {Enable ray mask support} {
    configure.args-append   -DEMBREE_RAY_MASK=ON
}

variant backface_culling description {Enable back-face culling} {
    configure.args-append   -DEMBREE_BACKFACE_CULLING=ON
}

# Note: Other than the tutorials, please keep this port's default
# variants synchronized with the flags used by Blender when it compiles
# Embree as an internal dependency. These flags can be found in the
# build_files/build_environment/install_deps.sh script in Blender's
# source code.
default_variants    +tutorials +ray_mask

# do not find "-alpha" versions
github.livecheck.regex  {([0-9.]+)}
