# -*- 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
PortGroup           legacysupport 1.1

github.setup        KhronosGroup SPIRV-Tools 1.4.321.0 vulkan-sdk-
github.tarball_from archive
name                spirv-tools
revision            0

categories          graphics
license             Apache-2
maintainers         {judaew @judaew} openmaintainer

description         various SPIR-V tools
long_description    SPIR-V assembler, binary module parser, \
                    disassembler, validator, and optimizer
homepage            https://vulkan.lunarg.com

# FIXME : main module not extracted in worksrcpath when using multiple sources.
# move extracted main module to worksrcpath
# Move submodules to cmakes expected location in worksrcpath
post-extract {
    move ${workpath}/SPIRV-Tools-${github.tag_prefix}${version} ${worksrcpath}
    foreach {sub_author sub_project sub_commit sub_dest} ${submodules} {
        move ${workpath}/${sub_project}-${sub_commit} ${worksrcpath}/${sub_dest}
    }
}

checksums           SPIRV-Tools-${version}.tar.gz \
                    rmd160  b5541a39f2dbeff47dd5e1386193d4885b3628c9 \
                    sha256  8327fb8f3e9472346a004c91dbb83a6e5f3b36c3846c142cf8c0dc8fac8710f3 \
                    size    3336926 \
                    abseil-cpp-20250512.1.tar.gz \
                    rmd160  8b0a057d2cb9a6f60e93a5c526beb328906cce52 \
                    sha256  9b7a064305e9fd94d124ffa6cc358592eb42b5da588fb4e07d09254aa40086db \
                    size    2221441 \
                    effcee-8ce15c424e61a94ee27b5be0ec0ed036b158e6e3.tar.gz \
                    rmd160  205ff8af4a660060f78f24abecb91f34a5a7a498 \
                    sha256  ca22a22e794b5f2ab164f43085a1cf864d8839e3fc30733c5aaa7c6d56ad0f41 \
                    size    41350 \
                    googletest-35b75a2cba6ef72b7ce2b6b94b05c54ca07df866.tar.gz \
                    rmd160  f64f209de2447b01aca55335588c35998a0be02e \
                    sha256  b46a96e802481ce29418a018daeebcabd77e94c91fd0bec2b3ea900baa9f6df0 \
                    size    888219 \
                    protobuf-f0dc78d7e6e331b8c6bb2d5283e06aa26883ca7c.tar.gz \
                    rmd160  a397c44d602407d85eb6ac6b985f9feb792f76e1 \
                    sha256  d594b561fb41bf243233d8f411c7f2b7d913e5c9c1be4ca439baf7e48384c893 \
                    size    5146983 \
                    re2-c84a140c93352cdabbfb547c531be34515b12228.tar.gz \
                    rmd160  88a8a9edc11672acc990a6502464b54eb3caadc3 \
                    sha256  94ad73bd2b32177874239bbb0a59625901212252751518c27f87f78d191c36ad \
                    size    391028 \
                    SPIRV-Headers-2a611a970fdbc41ac2e3e328802aed9985352dca.tar.gz \
                    rmd160  39f4f3dab756478d7567ed7185efedde13803703 \
                    sha256  c2225a49c3d7efa5c4f4ce4a6b42081e6ea3daca376f3353d9d7c2722d77a28a \
                    size    538726

compiler.cxx_standard 2017
# Need to use MacPorts libc++ on macOS 10.14 Mojave and older, because
# Apple Clang only added support for the C++17 <filesystem> library
# starting in Xcode 11 (clang-1100) for macOS 10.15+.
#
# References:
# * https://stackoverflow.com/a/55353263
# * https://developer.apple.com/documentation/xcode-release-notes/xcode-11-release-notes
legacysupport.newest_darwin_requires_legacy 18
legacysupport.use_mp_libcxx yes

set py_ver          3.13
set py_ver_nodot    [string map {. {}} ${py_ver}]
foreach stage {configure build destroot test} {
    ${stage}.env-append PATH=${frameworks_dir}/Python.framework/Versions/${py_ver}/bin:$env(PATH)
}
depends_build-append port:python${py_ver_nodot}

# See DEPS file in repo
# Exept abseil changed to lts version.
set submodules {
    abseil abseil-cpp 20250512.1 external/abseil_cpp
    google effcee 8ce15c424e61a94ee27b5be0ec0ed036b158e6e3 external/effcee
    google googletest 35b75a2cba6ef72b7ce2b6b94b05c54ca07df866 external/googletest
    protocolbuffers protobuf f0dc78d7e6e331b8c6bb2d5283e06aa26883ca7c external/protobuf
    google re2 c84a140c93352cdabbfb547c531be34515b12228 external/re2
    KhronosGroup SPIRV-Headers 2a611a970fdbc41ac2e3e328802aed9985352dca external/spirv-headers
}

foreach {sub_author sub_project sub_commit sub_dest} ${submodules} {
    master_sites-append https://github.com/${sub_author}/${sub_project}/archive/${sub_commit}.tar.gz?dummy=:${sub_project}
    distfiles-append    ${sub_project}-${sub_commit}.tar.gz:${sub_project}
}

configure.args-append \
                    -DSPIRV_WERROR=OFF \
                    -DBUILD_SHARED_LIBS=ON \
                    -DSPIRV_TOOLS_BUILD_STATIC=OFF \
                    -DCMAKE_INSTALL_PREFIX=${prefix}
