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

github.setup        KhronosGroup SPIRV-Tools 1.4.328.1 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  ad9add19f9c79d6bac0c22bf920a94c0afeb9642 \
                    sha256  d00dc47df7163c2bacd70f090441e8fad96234f0e3b96c54ee9091a49e627adb \
                    size    3393746 \
                    abseil-cpp-e32d1eb466fd53f81830591045be2e4845c626c3.tar.gz \
                    rmd160  fe7bf354501afbee76cee22b3c4e1cbe8744c667 \
                    sha256  dc1ab85273e597bb0d7fbf1aa018a4794ecd9a9eecc3f436dbd7eb34c2b11c66 \
                    size    2259933 \
                    effcee-514b52ec61609744d7e587d93a7ef9b60407ab45.tar.gz \
                    rmd160  8f660fd9db7cba7de45c04fe12165ca56fb347c3 \
                    sha256  3376aabe01b343753641110e5c3403f3705b6eb98825246f200cc3d9e0b41edd \
                    size    41155 \
                    googletest-1b96fa13f549387b7549cc89e1a785cf143a1a50.tar.gz \
                    rmd160  fa0a0d43eb2994c5892fb7787b1f8bed11cef405 \
                    sha256  44732cdd185c579c33d7aa70f40c47dcfd9fc3ffac28a3e42cea0e257d7d5c2c \
                    size    889186 \
                    protobuf-f0dc78d7e6e331b8c6bb2d5283e06aa26883ca7c.tar.gz \
                    rmd160  a397c44d602407d85eb6ac6b985f9feb792f76e1 \
                    sha256  d594b561fb41bf243233d8f411c7f2b7d913e5c9c1be4ca439baf7e48384c893 \
                    size    5146983 \
                    re2-e7aec5985072c1dbe735add802653ef4b36c231a.tar.gz \
                    rmd160  be95bdfa81cbb7ab41235a3de04f7aac3f9b6f0c \
                    sha256  f7f9bb4b56012c069d9428f5dd6480309a46a05921412c8150e01eac8a0be6da \
                    size    397966 \
                    SPIRV-Headers-b824a462d4256d720bebb40e78b9eb8f78bbb305.tar.gz \
                    rmd160  3a4ae286af7a471cffa157b99289304b7f2a583e \
                    sha256  c693867f10a7760ef1bcf85419d51783586768cc2c601d03841bc6a8b2554b9c \
                    size    558965

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 e32d1eb466fd53f81830591045be2e4845c626c3 external/abseil_cpp
    google effcee 514b52ec61609744d7e587d93a7ef9b60407ab45 external/effcee
    google googletest 1b96fa13f549387b7549cc89e1a785cf143a1a50 external/googletest
    protocolbuffers protobuf f0dc78d7e6e331b8c6bb2d5283e06aa26883ca7c external/protobuf
    google re2 e7aec5985072c1dbe735add802653ef4b36c231a external/re2
    KhronosGroup SPIRV-Headers b824a462d4256d720bebb40e78b9eb8f78bbb305 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}

conflicts_build     gtest
