# -*- 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.350.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  a8279c334893e1620ef93e30d560025088f5d70c \
                    sha256  6f7b9b9eed9a7aa485918466ea604b4edc7969d94e96c0c13ae266f4ec120f31 \
                    size    3472729 \
                    abseil-cpp-351086314d46e73d430296c9eca1f6d6c0372cd1.tar.gz \
                    rmd160  58c5d4edb76201e696bb41108713f933c007c243 \
                    sha256  d52a60908e791075d807dfe8db766a236abfac5c0c6e1e84023d83724948b75d \
                    size    2357079 \
                    effcee-ae38e040cbb7e83efa8bfbb4967e5b8c8c89b55a.tar.gz \
                    rmd160  bdbe73f2480488957c2bc28a8251b02e6ab565f1 \
                    sha256  cae1288f65c3f71f3a588136483a26482450f787a535c97f05689a4b0c858947 \
                    size    41184 \
                    googletest-d72f9c8aea6817cdf1ca0ac10887f328de7f3da2.tar.gz \
                    rmd160  c1ad84f90d6bde0c2ad1d3c56ceea4f59d0dad5c \
                    sha256  59d6b38b0daf41b7fa922e3cc1fc54aace4b823d7a51300386336a854fe03a60 \
                    size    890871 \
                    protobuf-f0dc78d7e6e331b8c6bb2d5283e06aa26883ca7c.tar.gz \
                    rmd160  a397c44d602407d85eb6ac6b985f9feb792f76e1 \
                    sha256  d594b561fb41bf243233d8f411c7f2b7d913e5c9c1be4ca439baf7e48384c893 \
                    size    5146983 \
                    re2-972a15cedd008d846f1a39b2e88ce48d7f166cbd.tar.gz \
                    rmd160  dbe18578bbf0b765589da144592985a71f8e713c \
                    sha256  cd4a75bdc0ec2e2506026ea4ccc9f0c429aceab8b6305b2cd30a1f4cc67644bc \
                    size    398012 \
                    SPIRV-Headers-ad9184e76a66b1001c29db9b0a3e87f646c64de0.tar.gz \
                    rmd160  6c6c7d8c739e59047e7e93f6a23df7a5784cb127 \
                    sha256  b5b7eba62453eb8c6f6a5fbf7155b71cde693bafe9cd5f03b79ed8c714816afe \
                    size    565709 \
                    mimalloc-b1963961a5cdb1996c9ad2e356014089b7a94ea3.tar.gz \
                    rmd160  0d95089c2b1d3679229b13a5caed190889969324 \
                    sha256  9ab197701a22fcfaa60f569957925c4d01bf0f8ebc7baa56e55f20f3d00c3644 \
                    size    1376914

cmake.build_type    Release

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.14
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 351086314d46e73d430296c9eca1f6d6c0372cd1 external/abseil_cpp
    google effcee ae38e040cbb7e83efa8bfbb4967e5b8c8c89b55a external/effcee
    google googletest d72f9c8aea6817cdf1ca0ac10887f328de7f3da2 external/googletest
    protocolbuffers protobuf f0dc78d7e6e331b8c6bb2d5283e06aa26883ca7c external/protobuf
    google re2 972a15cedd008d846f1a39b2e88ce48d7f166cbd external/re2
    KhronosGroup SPIRV-Headers ad9184e76a66b1001c29db9b0a3e87f646c64de0 external/spirv-headers
    microsoft mimalloc b1963961a5cdb1996c9ad2e356014089b7a94ea3 external/mimalloc
}

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
