# -*- 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.363.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  0f046dfc9a67f83fd8e879e4ead1007f8385130b \
                    sha256  e6c83a215538fbfd265ccf398d3877985055df1273dbed73912bd05307664688 \
                    size    3556753 \
                    abseil-cpp-d203903a1d02bfa22b044094e0638232ce99d305.tar.gz \
                    rmd160  f04fb229a6a6e4422050b435d44adf0c92bf69be \
                    sha256  9697872011781d1b61f52f05d7b991b6280ad62a4192be06f89c00403f69f133 \
                    size    2433143 \
                    effcee-f8e8a164822d4f65e757bff66bc00e1567959aa0.tar.gz \
                    rmd160  460d0c3386e53071f0625fbc039bc93cc4828e1e \
                    sha256  7c3f76f36d591578db29f0fa9abf16826a091b6da654a2797a84b88bf264cf52 \
                    size    41518 \
                    googletest-283c17563fe7a1111cd7f581aa5d541e8baeff2f.tar.gz \
                    rmd160  ae1c0e1804276226cbaaf1ae6a97ec46a1861e2e \
                    sha256  836c7aa5ef074eae6a1924a580599ad17da25c647612a578516b4a9737449801 \
                    size    894266 \
                    protobuf-35cd01f9fe9afbeea38cc7b979a3b6bfcde82c03.tar.gz \
                    rmd160  b728238e02b8396350d92587d7c4093127cb14c4 \
                    sha256  f8264c6e56b1fe59d06aa1b99ee81f76246ed2b46cf2c86b8a50f8482fa05665 \
                    size    7162956 \
                    re2-972a15cedd008d846f1a39b2e88ce48d7f166cbd.tar.gz \
                    rmd160  dbe18578bbf0b765589da144592985a71f8e713c \
                    sha256  cd4a75bdc0ec2e2506026ea4ccc9f0c429aceab8b6305b2cd30a1f4cc67644bc \
                    size    398012 \
                    SPIRV-Headers-496543121ce6419f23d6fa5d7194ba66c36212d2.tar.gz \
                    rmd160  6c1ff552bcc8c25e57b64d18a1d34c3d774b789d \
                    sha256  a9bb9c48713245eacf97cc539b6f1d45405a92d8813f8b82e635f0a085ee9898 \
                    size    594379 \
                    mimalloc-c9cc3394059edfb018ca2906753c4b0e857df00c.tar.gz \
                    rmd160  3e286b4da4720480bb52df10e1d9fde023af2b0e \
                    sha256  ddb838b4676b4ec9cc837cf74193d909526f2a6f4ee1690fa5e437ec3e081d07 \
                    size    1444456

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 d203903a1d02bfa22b044094e0638232ce99d305 external/abseil_cpp
    google effcee f8e8a164822d4f65e757bff66bc00e1567959aa0 external/effcee
    google googletest 283c17563fe7a1111cd7f581aa5d541e8baeff2f external/googletest
    protocolbuffers protobuf 35cd01f9fe9afbeea38cc7b979a3b6bfcde82c03 external/protobuf
    google re2 972a15cedd008d846f1a39b2e88ce48d7f166cbd external/re2
    KhronosGroup SPIRV-Headers 496543121ce6419f23d6fa5d7194ba66c36212d2 external/spirv-headers
    microsoft mimalloc c9cc3394059edfb018ca2906753c4b0e857df00c 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
