# -*- 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        KhronosGroup SPIRV-Cross 1.1.5 MoltenVK-
github.tarball_from archive

name                spirv-cross
# This version number is taken from the spirv-cross-c library (i.e.
# the C API), and is obtained by looking in the file
# ${worksrcpath}/spirv_cross_c.h, as defined by SPVC_C_API_VERSION_*.
version             0.48.0
revision            0

categories          graphics
license             Apache-2
maintainers         @jasonliu-- openmaintainer

description         tool for parsing and converting SPIR-V to and from \
                    other shader languages
long_description    ${github.project} is a tool and library for \
                    performing reflection on SPIR-V and disassembling \
                    SPIR-V back to high-level languages.

checksums           rmd160  ac0aab7c3fb854ab95dcee09cb0c0f0b2ef85fd9 \
                    sha256  e11845d9a4ccb4666923a8b678935cf78acad2b4fc131aba779f5bcc6def5191 \
                    size    1514658

compiler.cxx_standard   2011

configure.args-append   -DSPIRV_CROSS_SHARED=ON \
                        -DSPIRV_CROSS_FORCE_PIC=ON \
                        -DSPIRV_CROSS_ENABLE_TESTS=OFF

pre-test {
    if {![variant_isset tests]} {
        ui_error "'tests' variant must be activated to enable test support"
        error "Please enable the 'tests' variant and try again"
    }
}

variant tests description {Build unit tests} {
    set py_ver              3.11
    set py_ver_nodot        [string map {. {}} ${py_ver}]

    depends_lib-append      port:glslang \
                            port:spirv-tools

    post-patch {
        # Make it so that the CMake build is able to find the tools
        # that are available through MacPorts
        reinplace -E \
            "/(glslang|spirv-tools)-build/s,(PATHS ).*(bin),\\1${prefix}/\\2," \
            ${worksrcpath}/CMakeLists.txt
    }

    depends_test-append     port:python${py_ver_nodot}
    configure.python        ${prefix}/bin/python${py_ver}
    configure.args-append   -DPYTHON_EXECUTABLE:FILEPATH=${configure.python}

    configure.args-replace  -DSPIRV_CROSS_ENABLE_TESTS=OFF \
                            -DSPIRV_CROSS_ENABLE_TESTS=ON
    test.run yes
}
