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

name                        qt6

categories                  aqua
platforms                   {macosx >= 23} ; # upon change, please update qt6 PG
maintainers                 {mcalhoun @MarcusCalhoun-Lopez} \
                            {reneeotten @reneeotten} openmaintainer

# for OpenSSLException, see source and header files in src/network/ssl of qtbase
# see also https://doc.qt.io/qt-6/qtnetwork-index.html#licenses-and-attributions
license                     {LGPL-3 GPL-3 OpenSSLException}

homepage                    https://www.qt.io

version                     6.11.1

# get Qt's version numbers
set branch                  [join [lrange [split ${version} .] 0 1] .]
set qt_major                [lindex [split ${version} .] 0]

# see https://www.qt.io/blog/qt-6.11-released
compiler.c_standard         2011
compiler.cxx_standard       2017

# qcompilerdetection.h emits:
#     error: "Unsupported Apple Clang version"
# which also means Q_CC_CLANG will not be set.
# That causes the check for __has_feature(cxx_unicode_literals) to be skipped, causing
#     error: "Qt6 requires Unicode string support in both the compiler and the standard library"
# to be emitted, even when the unsupported Apple Clang version does support Unicode string literals.
compiler.blacklist-append   {clang < 1100}

master_sites                https://download.qt.io/official_releases/qt/${branch}/${version}/submodules
# file sizes are significantly smaller using xz
use_xz                      yes

supported_archs             arm64 x86_64

# conflict with all other versions of qt6
foreach {qt_base qt_info} ${qt6::available_versions} {
    if { ${qt_base} ne ${name} } {
        conflicts-append    ${qt_base}-qtbase
    }
}

if {${os.platform} eq "darwin" && [vercmp ${macosx_deployment_target} >= 15.0]} {
    macosx_deployment_target 14.0
}

# cannot get qt6-qtbase to configure without setting this
use_xcode                   yes

# MacPorts LLVM/Clang version to use when required
set llvm_version            22

# MacPorts Python branch & version to use when required
set python_branch           3.14
set python_version          [join [split ${python_branch} .] ""]

# build of certain Qt6 components fail when zstdConfig.cmake is installed
# see: https://trac.macports.org/ticket/72923
conflicts_build zstdConfig.cmake

############################################################################### Modules Not Considered
#
# No qtactiveqt      (Windows Only)
# No qtwayland       (Linux Only)
#
###############################################################################

############################################################################### Qt Dependencies
#
# https://code.qt.io/cgit/qt/qt5.git/tree/.gitmodules?h=6.11.0
#
###############################################################################

############################################################################### Module Format
#
# "Qt Module Name" {
#     {
#         checksum, rmd160
#         checksum, sha256
#         checksum, size
#     }
#     dependencies, build
#     dependencies, lib
#     dependencies, Qt module name
#     Qt components provided
#     included in "standard" installation of Qt (empty string is no, explanation string is yes)
#     variant overrides
#     revision number
#     license replacement
# }
#
# module info found at https://doc.qt.io/qt-6/qtmodules.html
#
###############################################################################
array set modules {
    qtbase {
        {
            0426ec296ed3d4f75fca7c67a9b2cdf0fa61eee7 \
            d9594a31228aa23ad6b531719a29b45f0f3989fe6c136d45767ea179f233c1ac \
            50648500
        }
        ""
        "port:brotli port:dbus port:double-conversion port:freetype
            path:lib/pkgconfig/glib-2.0.pc:glib2 path:lib/pkgconfig/harfbuzz.pc:harfbuzz
            path:lib/pkgconfig/icu-uc.pc:icu path:include/turbojpeg.h:libjpeg-turbo port:libb2
            port:libpng port:md4c path:lib/pkgconfig/libpcre2-posix.pc:pcre2
            port:zlib path:lib/pkgconfig/libzstd.pc:zstd"
        ""
        {"Qt Core" "Qt GUI" "Qt Network" "Qt SQL" "Qt Test" "Qt Widgets" "Qt Concurrent" "Qt D-Bus" \
         "Qt OpenGL" "Qt Platform Headers" "Qt Print Support" "Qt XML"}
        ""
        "variant overrides: "
        "revision 1"
        "License: "
    }
    qtsvg {
        {
            c81b64d4609a6d54aa1ece5e6fa046d9d3862cf7 \
            7f3cf02f4824bf03c2c5859ea6db173bf1482a1daf24e6cdf7bc78cfa26a8a94 \
            2336944
        }
        ""
        "port:zlib"
        "qtbase"
        {"Qt SVG"}
        ""
        "variant overrides: "
        "revision 0"
        "License: "
    }
    qtdeclarative {
        {
            651f1daa71abf1a90d9064cfb5725e35b4464517 \
            52e670f670b0304f534b24f98c47ceb8a41bb710464414ebc9527ec71cc86aa4 \
            38744644
        }
        ""
        ""
        "qtbase qtimageformats qtshadertools qtsvg qtlanguageserver"
        {"Qt QML" "Qt Quick" "Qt Quick Layouts" "Qt Quick Widgets"}
        ""
        "variant overrides: "
        "revision 0"
        "License: "
    }
    qtmultimedia {
        {
            f34b0424e3079e50db27724753b05bd0075f2d8b \
            390f8e52ddee3aca5c4de7eead900c84c4fa61ff6d1f0ebea9c7543365c09b0a \
            10243896
        }
        ""
        "port:ffmpeg8 port:pulseaudio"
        "qtbase qtshadertools qtdeclarative qtquick3d"
        {"Qt Multimedia"}
        ""
        "variant overrides: "
        "revision 0"
        "License: "
    }
    qttools {
        {
            4ffbe874f5f3f9b55dfa2030e39e53aa06977f31 \
            8e61835a679c93fa9c6065b142353c2071ba68e297898937c32a03777fcaf50d \
            10225832
        }
        ""
        "port:clang-${llvm_version} path:lib/pkgconfig/libzstd.pc:zstd"
        "qtbase qtdeclarative"
        {"Qt Designer" "Qt Help" "Qt UI Tools"}
        ""
        "variant overrides: "
        "revision 0"
        "License: "
    }
    qttranslations {
        {
            efc7dfab4b361d4c77ddd173775368b3e1624b1a \
            37c02c81206594c7bb4edca85ac93e8e55a9836b70c960fde6cb0f8623ec5677 \
            1684616
        }
        ""
        ""
        "qttools"
        {"translation files"}
        ""
        "variant overrides: ~examples ~tests ~debug noarch ~docs"
        "revision 0"
        "License: "
    }
    qtdoc {
        {
            82114c3b41ecaddbf23670a37305ab60764bd9cc \
            068cb2881447dcf1baa00514dde2dc944a1f85cdd6cfdff9c84b8b9eaff9a5c1 \
            49989612
        }
        ""
        ""
        "qtdeclarative qttools qtmultimedia"
        {"documentation and examples"}
        ""
        "variant overrides: "
        "revision 0"
        "License: "
    }
    qtlocation {
        {
            2165970f4ec99f308c7bae42d5ed0cdf98f0b6a8 \
            3791ce77299e6f600a593d0fbfa5bd32fbcfc2d16104782b84acc489e382e41b \
            3151756
        }
        ""
        ""
        "qtbase qtpositioning qtdeclarative"
        {"Qt Location"}
        "status = preview"
        "variant overrides: "
        "revision 0"
        "License: "
    }
    qtpositioning {
        {
            b067480c35f917b3d8b0528a03a3718ffe21a5e9 \
            d5e6b91801ae286e7630016caea3bdc5e1978b4291d6741d0d64c125650f78f5 \
            653096
        }
        ""
        "port:gconf port:gettext-runtime path:lib/pkgconfig/glib-2.0.pc:glib2"
        "qtbase qtdeclarative qtserialport"
        {"Qt Positioning"}
        ""
        "variant overrides: ~examples ~tests"
        "revision 0"
        "License: "
    }
    qtsensors {
        {
            3684729a534640441a939fcfdc4f732c28a8d930 \
            23617062da7be526d023dec7f9b76231001a1098a7e5f94c646f2e4f87cfcf8f \
            1485472
        }
        ""
        ""
        "qtbase qtdeclarative"
        {"Qt Sensors"}
        ""
        "variant overrides: "
        "revision 0"
        "License: "
    }
    qtconnectivity {
        {
            380e59b2d40deecbc721b94b151ce58dcfe9c943 \
            2105289ea414b46ed5fa53ba8782230045b9e47cc8156b5940c9e31e3980e591 \
            1059432
        }
        ""
        ""
        "qtbase qtdeclarative"
        {"Qt Bluetooth" "Qt NFC"}
        ""
        "variant overrides: "
        "revision 0"
        "License: "
    }
    qt3d {
        {
            fe6ea9044f857517ca16b03b30725e49418de63b \
            a66d8c8e049d1ee7a7687b34940f3555d0d7084858b6dc78d1e1cb7df40a0107 \
            141869788
        }
        ""
        "port:assimp port:zlib port:minizip port:pugixml"
        "qtbase qtdeclarative qtshadertools"
        {"Qt 3D"}
        "status = deprecated"
        "variant overrides: "
        "revision 0"
        "License: "
    }
    qtimageformats {
        {
            1a7e9bae31648663d34d68ffc0cc87266a620ed5 \
            b2bf6c6845ac175ed7f819145483ba4676f617aaa6a5012c8efee63c8bbac413 \
            2032792
        }
        ""
        "path:lib/pkgconfig/jasper.pc:jasper port:libmng port:tiff port:webp
            path:include/turbojpeg.h:libjpeg-turbo"
        "qtbase"
        {"Qt Image Formats"}
        ""
        "variant overrides: "
        "revision 0"
        "License: "
    }
    qtserialbus {
        {
            d92e5c4af7b4f08b61a03dffb1472577ecc9439c \
            c46c9c0c8d6815301a669cdbd5866c10bcfb9e56889f5d7da14e11d6ad24f20a \
            535680
        }
        ""
        ""
        "qtbase qtserialport"
        {"Qt Serial Bus"}
        ""
        "variant overrides: "
        "revision 0"
        "License: "
    }
    qtserialport {
        {
            80113b871a9cf88a9826eb289a225c966a490857 \
            9af31a898ffd9a7e4faf6fed845d29e783c716885789055cbe319f3e072d3974 \
            264092
        }
        ""
        ""
        "qtbase"
        {"Qt Serial Port"}
        ""
        "variant overrides: "
        "revision 0"
        "License: "
    }
    qtwebsockets {
        {
            1953582c474db76ecd15b07198dcb019ef684a5f \
            243e3aa11924c8c5c1645e892f62d013caa3766c57512ca926d5b58146646fbf \
            452228
        }
        ""
        ""
        "qtbase qtdeclarative"
        {"Qt WebSockets"}
        ""
        "variant overrides: "
        "revision 0"
        "License: "
    }
    qtwebchannel {
        {
            a54f918b00a67c94811650442312e95b1b7a7dee \
            69fbb50b71d6e6596c2d6863ee9a9c984a4d01378ee2b7b4163bb467a0158d82 \
            193204
        }
        ""
        ""
        "qtbase qtdeclarative qtwebsockets"
        {"Qt WebChannel"}
        ""
        "variant overrides: "
        "revision 0"
        "License: "
    }
    qtwebengine {
        {
            83dea1ac9249dfe8d5aaeade56f8dcba1a4a64dc \
            679c66ccc6c158fc215e9c58ef160331ecd29974232e345c05161889f8667083 \
            578914356
        }
        "path:bin/node:nodejs22 port:python${python_version} port:py${python_version}-html5lib port:py${python_version}-ply"
        "port:libpng port:zlib"
        "qtdeclarative qtwebchannel qttools qtpositioning"
        {"Qt WebEngine Qt" "Qt PDF"}
        ""
        "variant overrides: "
        "revision 0"
        "License: "
    }
    qtwebview {
        {
            a15be56aa5a4e6c16cb836ad2d1676bfb7fa2bdb \
            8d62c8ef70d58260e9b3e8b5fc1a8bc48495308a4437003a394483757427133d \
            128608
        }
        ""
        ""
        "qtdeclarative qtwebengine"
        {"Qt WebView"}
        ""
        "variant overrides: "
        "revision 0"
        "License: "
    }
    qtcharts {
        {
            415fac6b5e94022989c0a8fc4e300b4b1a6b1fcb \
            3fe3ed318c2a86d1417c5c29cf7494275e8fd4b537cd37453f5599c57365515c \
            4651704
        }
        ""
        ""
        "qtbase qtdeclarative qtmultimedia"
        {"Qt Charts"}
        "GPLv3 license only"
        "variant overrides: "
        "revision 0"
        "License: {GPL-3 OpenSSLException}"
    }
    qtdatavis3d {
        {
            94ee0b258f910436317bb6d9e4e6c73b86f4f7cd \
            1e1a7b9c0a947731655334f5d79252d40cdaf58c1801074ea5e9e0821d6693ac \
            3939800
        }
        ""
        ""
        "qtbase qtdeclarative qtmultimedia"
        {"Qt Data Visualization"}
        "status = deprecated; GPLv3 license only"
        "variant overrides: "
        "revision 0"
        "License: {GPL-3 OpenSSLException}"
    }
    qtvirtualkeyboard {
        {
            81555b582f72d23209e9b182455d8c8d6f12c61f \
            a1c6967b326243b2ca8d50bc7b7f7852c3975d9aa6ce4b186ebdf35bb1007e1c \
            3293452
        }
        ""
        "port:hunspell"
        "qtbase qtdeclarative qtsvg qtmultimedia"
        {"Qt Virtual Keyboard"}
        "GPLv3 license only"
        "variant overrides: "
        "revision 0"
        "License: {GPL-3 OpenSSLException}"
    }
    qtscxml {
        {
            387970e98d81f42f395a4151d5cffee0665a1e4d \
            8e495245e5d1fe75de612c8a07e4043635407a1979bb1dd588f1751d1390203f \
            550144
        }
        ""
        ""
        "qtbase qtdeclarative"
        {"Qt SCXML"}
        ""
        "variant overrides: "
        "revision 0"
        "License: "
    }
    qtspeech {
        {
            5c47228e8ae336f1b451d811a1cc5fc977cae221 \
            c035c318012025875a653245701a23d3807e8e46b8bf7987877842219c273f14 \
            249232
        }
        ""
        "port:flite"
        "qtbase qtdeclarative qtmultimedia"
        {"Qt TextToSpeech"}
        ""
        "variant overrides: "
        "revision 0"
        "License: "
    }
    qtnetworkauth {
        {
            12558fd5e73f2a10160680752ca5b66ce7384057 \
            9f1d5bf22ccc033e42076186b964f9d4d4179fd0312a2c0f1aa19db42516563d \
            435572
        }
        ""
        ""
        "qtbase"
        {"Qt Network Authorization"}
        "GPLv3 license only"
        "variant overrides: "
        "revision 0"
        "License: {GPL-3 OpenSSLException}"
    }
    qtremoteobjects {
        {
            13d16cdbe84c41a87f11001ce3ea8a97a626743b \
            40629895c69531a687a9c0258316cee3f04c2d18b2bf2ad36dc83e76a58f111a \
            529300
        }
        ""
        ""
        "qtbase qtdeclarative"
        {"Qt Remote Objects"}
        ""
        "variant overrides: "
        "revision 0"
        "License: "
    }
    qtlottie {
        {
            2318b3a1b1bbde23609b6d2077b42c85e08b5eb2 \
            e0d0fadbdc33e97c8241c56273b54b6a7b1139e076fdd21281bc4662ee4b2679 \
            663580
        }
        ""
        ""
        "qtbase qtdeclarative"
        {"Qt Lottie Animation"}
        "GPLv3 license only"
        "variant overrides: "
        "revision 0"
        "License: {GPL-3 OpenSSLException}"
    }
    qtquicktimeline {
        {
            9e8e32ea60276c856cc03b94ffbf2ed4065d0fe8 \
            af53f643fd9e4045e1b9ba919998e5c048ca877452c08036c9c8c5ee07ea8c27 \
            97268
        }
        ""
        ""
        "qtbase qtdeclarative"
        {"Qt Quick Timeline"}
        "GPLv3 license only"
        "variant overrides: "
        "revision 0"
        "License: {GPL-3 OpenSSLException}"
    }
    qtquick3d {
        {
            a44f4730b0e94c33e64b6316978dd1c81d2791fa \
            c76b85de3f8aa2a4bee64987acfef560675c1b378b92076c7c6264613e5b456f \
            69622816
        }
        ""
        "port:assimp"
        "qtbase qtdeclarative qtshadertools"
        {"Qt Quick 3D"}
        "GPLv3 license only"
        "variant overrides: "
        "revision 0"
        "License: {GPL-3 OpenSSLException}"
    }
    qtshadertools {
        {
            c0fc139d195c551456eb61fe4656ac971dd22ad2 \
            2075052f9b23bcf9de045bbd180037084942f82cce870aab14a1454902c982fc \
            1216568
        }
        ""
        ""
        "qtbase"
        {"Qt Shader Tools"}
        ""
        "variant overrides: "
        "revision 0"
        "License: "
    }
    qt5compat {
        {
            a5fb950aa4fa00474b620728da8dbd7c811fa1e0 \
            cfcb9fdaa051aad54b0e61b24ac5693b4887a86e07609f665fea67328a6f161b \
            14621480
        }
        ""
        "path:lib/pkgconfig/icu-uc.pc:icu port:libiconv"
        "qtbase qtdeclarative"
        {"Qt 5 Core Compatibility APIs"}
        "status = deprecated"
        "variant overrides: "
        "revision 1"
        "License: "
    }
    qtlanguageserver {
        {
            0acc18b5174f87aa112356766d123f2f65233c7a \
            50008537f2ca54abb3b8dc3f26759864e9cad2b2ad39e92e42fa718de2dd8aef \
            137276
        }
        ""
        ""
        "qtbase"
        {"Qt Language Server"}
        "status = preview"
        "variant overrides: ~docs"
        "revision 0"
        "License: "
    }
    qthttpserver {
        {
            023035800492eb94a1b63d6c023e8d7f98ccdc70 \
            04bf70fcf76861f9b6870c728085f2375a6b6d923cb5d1a116dff2ed52a4e706 \
            185072
        }
        ""
        ""
        "qtbase"
        {"Qt HTTP Server"}
        "GPLv3 license only"
        "variant overrides: "
        "revision 0"
        "License: {GPL-3 OpenSSLException}"
    }
    qtquick3dphysics {
        {
            12290e4ea767abd661ff8d41cdae0a98c8b73e62 \
            d1086d6f014e7b698945cf0ee1dc3e43545ed7dcf0b5e501c0d6836a96ac79af \
            4669964
        }
        ""
        ""
        "qtbase qtdeclarative qtquick3d qtshadertools"
        {"Qt Quick 3D Physics"}
        "GPLv3 license only"
        "variant overrides: "
        "revision 0"
        "License: {GPL-3 OpenSSLException}"
    }
    qtgrpc {
        {
            7092142aaf866cd5a0304946397b1e82ee013ab2 \
            437b04f0c550ccdb1739ca5f9119b73dfa0376564815e8bfc199890643e2a250 \
            753800
        }
        ""
        "port:abseil port:protobuf3-cpp"
        "qtbase qtdeclarative"
        {"Qt GRPC"}
        "GPLv3 license only"
        "variant overrides: "
        "revision 1"
        "License: {GPL-3 OpenSSLException}"
    }
    qtquickeffectmaker {
        {
            839f41bbc28fb14598fd9d32139f11430d5c57b5 \
            cfe63e70e88bdd126a175762d3eeb38eb336e45beceedcbd027bc5362744136b \
            4343420
        }
        ""
        ""
        "qtbase qtdeclarative qtquick3d qtshadertools"
        {"Qt Quick Effects"}
        ""
        "variant overrides: "
        "revision 0"
        ""
    }
    qtgraphs {
        {
            eddc8b290e40b7d686bfbe6714b102e2090c3f47 \
            84b1138ab68a8e2956439895a4b85eb68dda48ac169da673f67191873b1e0462 \
            9285696
        }
        ""
        ""
        "qtbase qtdeclarative qtquick3d"
        {"Qt Graphs"}
        ""
        "variant overrides: "
        "revision 0"
        "License: {GPL-3 OpenSSLException}"
    }
    qttasktree {
        {
            06fb5a7d28f5db1c1801f209ec3bf25b7eb4338e \
            a22ab97f8f4d37a4d6616d577b70edcac29fdf78b77c819eb0ef111187e74dd6 \
            257268
        }
        ""
        ""
        "qtbase"
        {"Qt TaskTree"}
        "status = preview"
        "variant overrides: "
        "revision 0"
        "License: {GPL-3 OpenSSLException}"
    }
    qtcanvaspainter {
        {
            761c7b84144a51fc048fe17e1d85e23409d35016 \
            9e36c61b10a5eb9b4a4af058996de5816d2c0d9f02415876ca8c0f8cccfd08d0 \
            713788
        }
        ""
        ""
        "qtbase qtdeclarative qtshadertools"
        {"Qt Canvas Painter"}
        "status = preview"
        "variant overrides: "
        "revision 0"
        "License: {GPL-3 OpenSSLException}"
    }
}

############################################################################### SQL Plugin Format
#
# {
#     module name
#     {
#         SQL name
#         revision string
#         {list of feature names}
#         {
#             variant name
#             {
#                 variant name
#                 library dependencies
#                 {list of CMake options to find library}
#             }
#         }
#     }
# }
#
###############################################################################
array set sql_plugins {
    sqlite {
        SQLite
        "revision 0"
        {sql-sqlite system-sqlite}
        {
            sqlite3 {
                "port:sqlite3"
                {
                    -DSQLite3_INCLUDE_DIR=${prefix}/include
                    -DSQLite3_LIBRARY=${prefix}/lib/libsqlite3.dylib
                }
            }
        }
    }
    psql {
        PostgreSQL
        "revision 0"
        {sql-psql}
        {
            postgresql17 {
                "port:postgresql17"
                {
                    -DPostgreSQL_INCLUDE_DIR=${prefix}/include/postgresql17
                    -DPostgreSQL_TYPE_INCLUDE_DIR=${prefix}/include/postgresql17
                    -DCMAKE_LIBRARY_PATH=${prefix}/lib/postgresql17
                }
            }
            postgresql16 {
                "port:postgresql16"
                {
                    -DPostgreSQL_INCLUDE_DIR=${prefix}/include/postgresql16
                    -DPostgreSQL_TYPE_INCLUDE_DIR=${prefix}/include/postgresql16
                    -DCMAKE_LIBRARY_PATH=${prefix}/lib/postgresql16
                }
            }
            postgresql15 {
                "port:postgresql15"
                {
                    -DPostgreSQL_INCLUDE_DIR=${prefix}/include/postgresql15
                    -DPostgreSQL_TYPE_INCLUDE_DIR=${prefix}/include/postgresql15
                    -DCMAKE_LIBRARY_PATH=${prefix}/lib/postgresql15
                }
            }
            postgresql14 {
                "port:postgresql14"
                {
                    -DPostgreSQL_INCLUDE_DIR=${prefix}/include/postgresql14
                    -DPostgreSQL_TYPE_INCLUDE_DIR=${prefix}/include/postgresql14
                    -DCMAKE_LIBRARY_PATH=${prefix}/lib/postgresql14
                }
            }
            postgresql13 {
                "port:postgresql13"
                {
                    -DPostgreSQL_INCLUDE_DIR=${prefix}/include/postgresql13
                    -DPostgreSQL_TYPE_INCLUDE_DIR=${prefix}/include/postgresql13
                    -DCMAKE_LIBRARY_PATH=${prefix}/lib/postgresql13
                }
            }
            postgresql12 {
                "port:postgresql12"
                {
                    -DPostgreSQL_INCLUDE_DIR=${prefix}/include/postgresql12
                    -DPostgreSQL_TYPE_INCLUDE_DIR=${prefix}/include/postgresql12
                    -DCMAKE_LIBRARY_PATH=${prefix}/lib/postgresql12
                }
            }
            postgresql11 {
                "port:postgresql11"
                {
                    -DPostgreSQL_INCLUDE_DIR=${prefix}/include/postgresql11
                    -DPostgreSQL_TYPE_INCLUDE_DIR=${prefix}/include/postgresql11
                    -DCMAKE_LIBRARY_PATH=${prefix}/lib/postgresql11
                }
            }
        }
    }
    mysql {
        MySQL
        "revision 0"
        {sql-mysql}
        {
            mariadb10_11 {
                "port:mariadb-10.11"
                {
                    -DMySQL_INCLUDE_DIR=${prefix}/include/mariadb-10.11/mysql
                    -DMySQL_LIBRARY=${prefix}/lib/mariadb-10.11/mysql/libmariadb.dylib
                }
            }
            mariadb10_10 {
                "port:mariadb-10.10"
                {
                    -DMySQL_INCLUDE_DIR=${prefix}/include/mariadb-10.10/mysql
                    -DMySQL_LIBRARY=${prefix}/lib/mariadb-10.10/mysql/libmariadb.dylib
                }
            }
            mariadb10_9 {
                "port:mariadb-10.9"
                {
                    -DMySQL_INCLUDE_DIR=${prefix}/include/mariadb-10.9/mysql
                    -DMySQL_LIBRARY=${prefix}/lib/mariadb-10.9/mysql/libmariadb.dylib
                }
            }
            mariadb10_8 {
                "port:mariadb-10.8"
                {
                    -DMySQL_INCLUDE_DIR=${prefix}/include/mariadb-10.8/mysql
                    -DMySQL_LIBRARY=${prefix}/lib/mariadb-10.8/mysql/libmariadb.dylib
                }
            }
            mariadb10_7 {
                "port:mariadb-10.7"
                {
                    -DMySQL_INCLUDE_DIR=${prefix}/include/mariadb-10.7/mysql
                    -DMySQL_LIBRARY=${prefix}/lib/mariadb-10.7/mysql/libmariadb.dylib
                }
            }
            mariadb10_6 {
                "port:mariadb-10.6"
                {
                    -DMySQL_INCLUDE_DIR=${prefix}/include/mariadb-10.6/mysql
                    -DMySQL_LIBRARY=${prefix}/lib/mariadb-10.6/mysql/libmariadb.dylib
                }
            }
            mariadb10_5 {
                "port:mariadb-10.5"
                {
                    -DMySQL_INCLUDE_DIR=${prefix}/include/mariadb-10.5/mysql
                    -DMySQL_LIBRARY=${prefix}/lib/mariadb-10.5/mysql/libmariadb.dylib
                }
            }
            mariadb10_4 {
                "port:mariadb-10.4"
                {
                    -DMySQL_INCLUDE_DIR=${prefix}/include/mariadb-10.4/mysql
                    -DMySQL_LIBRARY=${prefix}/lib/mariadb-10.4/mysql/libmariadb.dylib
                }
            }
            mysql8 {
                "port:mysql8"
                {
                    -DMySQL_INCLUDE_DIR=${prefix}/include/mysql8/mysql
                    -DMySQL_LIBRARY=${prefix}/lib/mysql8/mysql/libmysqlclient.dylib
                }
            }
        }
    }
}

foreach {module module_info} [array get modules] {
    subport ${name}-${module} {

        # minimum supported versions have changed over time and new qtXY ports were added
        # this attempts to provide a clean "upgrade" path for user who had  "qt6-XY" (sub)ports installed
        # on a system that is no longer supported
        if {${os.platform} eq "darwin" && ${os.major} < 23 && ${os.major} >= 21} {
            PortGroup               obsolete 1.0
            replaced_by             qt67-${module}
        } elseif {${os.platform} eq "darwin" && ${os.major} < 21 && ${os.major} >= 18} {
            PortGroup               obsolete 1.0
            replaced_by             qt64-${module}
        }

        distname                            ${module}-everywhere-src-${version}

        revision                            [regexp -inline {[0-9]+} [lindex ${module_info} 7]]

        checksums                           rmd160  [lindex [lindex ${module_info} 0] 0] \
                                            sha256  [lindex [lindex ${module_info} 0] 1] \
                                            size    [lindex [lindex ${module_info} 0] 2]

        set license_string                  [lindex ${module_info} 8]
        set license_string                  [string range ${license_string} 1+[string first ":" ${license_string}] end]
        set license_string                  [string trim ${license_string}]
        if { ${license_string} ne "" } {
            license                         {*}${license_string}
        }

        foreach deps [lindex ${module_info} 1] {
            depends_build-append            [subst ${deps}]
        }

        foreach deps [lindex ${module_info} 2] {
            depends_lib-append              [subst ${deps}]
        }

        foreach qtdeps [lindex ${module_info} 3] {
            depends_lib-append              port:${name}-${qtdeps}
        }

        description                         Tools and Module(s) for Qt Tool Kit ${qt_major}

        set modules_provided_list           [lindex ${module_info} 4]
        if { [llength ${modules_provided_list}] == 1 } {
            set modules_provided_join       [lindex ${modules_provided_list} 0]
        } elseif { [llength ${modules_provided_list}] == 2 } {
            set modules_provided_join       [join ${modules_provided_list} " and "]
        } else {
            set modules_provided_join       [join [list [join [lrange ${modules_provided_list} 0 end-1] ", "] [lindex ${modules_provided_list} end]] ", and "]
        }

        long_description                    Tools and Module(s) for Qt Tool Kit ${qt_major}: ${modules_provided_join}

        if { [lsearch -exact [lindex ${module_info} 6] "~universal"] != -1 } {
            universal_variant               no
        }

        if { [lsearch -exact [lindex ${module_info} 6] "noarch"] != -1 } {
            supported_archs                 noarch
            platforms                       any
        }

        if { [lsearch -exact [lindex ${module_info} 6] "~debug"] == -1 } {
            # debugging seems to be turned on if and only if it is turned on in the base
            # CMAKE_CONFIGURATION_TYPES is set with the FORCE option
            # see https://code.qt.io/cgit/qt/qtbase.git/tree/cmake/QtPostProcessHelpers.cmake
            variant debug description {Build both release and debug libraries} {
                require_active_variants     qt6-qtbase debug ""
            }
            if {![variant_isset debug]} {
                require_active_variants     qt6-qtbase "" debug
            }
        }

        if { [lsearch -exact [lindex ${module_info} 6] "~examples"] == -1 } {
            variant examples description {Build examples} {}
        }

        if { [lsearch -exact [lindex ${module_info} 6] "~tests"] == -1 } {
            variant tests description {Enable tests} {}
        }
    }
}

foreach {module module_info} [array get modules] {
    if { [lsearch -exact [lindex ${module_info} 6] "~docs"] != -1 } { continue }

    subport ${name}-${module}-docs {

        # minimum supported versions have changed over time and new qtXY ports were added
        # this attempts to provide a clean "upgrade" path for user who had  "qt6-XY" (sub)ports installed
        # on a system that is no longer supported
        if {${os.platform} eq "darwin" && ${os.major} < 23 && ${os.major} >= 21} {
            PortGroup               obsolete 1.0
            replaced_by             qt67-${module}-docs
        } elseif {${os.platform} eq "darwin" && ${os.major} < 21 && ${os.major} >= 18} {
            PortGroup               obsolete 1.0
            replaced_by             qt64-${module}-docs
        }

        distname                            ${module}-everywhere-src-${version}

        revision                            [regexp -inline {[0-9]+} [lindex ${module_info} 7]]

        checksums                           rmd160  [lindex [lindex ${module_info} 0] 0] \
                                            sha256  [lindex [lindex ${module_info} 0] 1] \
                                            size    [lindex [lindex ${module_info} 0] 2]

        set license_string                  [lindex ${module_info} 8]
        set license_string                  [string range ${license_string} 1+[string first ":" ${license_string}] end]
        set license_string                  [string trim ${license_string}]
        if { ${license_string} ne "" } {
            license                         {*}${license_string}
        }

        depends_build-append                port:${name}-qttools \
                                            port:${name}-sqlite-plugin

        # have the same build dependencies
        foreach deps [lindex ${module_info} 1] {
            depends_build-append [subst ${deps}]
        }

        depends_lib-append                  port:${name}-${module}

        description                         Documentation for Qt Tool Kit ${qt_major}

        set modules_provided_list           [lindex ${module_info} 4]
        if { [llength ${modules_provided_list}] == 1 } {
            set modules_provided_join       [lindex ${modules_provided_list} 0]
        } elseif { [llength ${modules_provided_list}] == 2 } {
            set modules_provided_join       [join ${modules_provided_list} " and "]
        } else {
            set modules_provided_join       [join [list [join [lrange ${modules_provided_list} 0 end-1] ", "] [lindex ${modules_provided_list} end]] ", and "]
        }

        long_description                    Documentation for Qt Tool Kit ${qt_major}: ${modules_provided_join}

        supported_archs                     noarch
        platforms                           any
    }
}

# see https://doc.qt.io/qt-6/sql-driver.html for info on building SQL Database Drivers
foreach {driver driver_info} [array get sql_plugins] {
    set dbms                                [lindex ${driver_info} 0]

    set revision_string                     [string trim [lindex ${driver_info} 1]]
    set revision_string                     [string range ${revision_string} 1+[string last " " ${revision_string}] end]

    set sql_variants                        [lindex ${driver_info} 3]

    subport ${name}-${driver}-plugin {

        # minimum supported versions have changed over time and new qtXY ports were added
        # this attempts to provide a clean "upgrade" path for user who had  "qt6-XY" (sub)ports installed
        # on a system that is no longer supported
        if {${os.platform} eq "darwin" && ${os.major} < 23 && ${os.major} >= 21} {
            PortGroup               obsolete 1.0
            replaced_by             qt67-${driver}-plugin
        } elseif {${os.platform} eq "darwin" && ${os.major} < 21 && ${os.major} >= 18} {
            PortGroup               obsolete 1.0
            replaced_by             qt64-${driver}-plugin
        }

        distname                            qtbase-everywhere-src-${version}

        revision                            ${revision_string}

        checksums                           rmd160  [lindex [lindex $modules(qtbase) 0] 0] \
                                            sha256  [lindex [lindex $modules(qtbase) 0] 1] \
                                            size    [lindex [lindex $modules(qtbase) 0] 2]

        depends_lib-append                  port:${name}-qtbase

        description                         ${dbms} Database Driver for Qt Tool Kit ${qt_major}
        long_description                    ${dbms} Database Driver for Qt Tool Kit ${qt_major}

        foreach feature {sql-db2 sql-ibase sql-mysql sql-oci sql-odbc sql-psql sql-sqlite system-sqlite} {
            if { ${feature} in [lindex ${driver_info} 2] } {
                configure.args-append       -feature-${feature}
            } else {
                configure.args-append       -no-feature-${feature}
            }
        }

        set worksrcpath                     ${worksrcpath}/src/plugins/sqldrivers

        set any_sql                         no
        foreach {variant_name variant_info} ${sql_variants} {
            set conflict_list ""

            foreach {variant_name_other variant_info_other} ${sql_variants} {
                if { ${variant_name_other} ne ${variant_name} } {
                    lappend conflict_list   ${variant_name_other}
                }
            }

            if { [llength ${conflict_list}] > 0 } {
                variant ${variant_name} conflicts {*}${conflict_list} description "use version [regexp -inline {[0-9].} ${variant_name}] of ${dbms}" {}
            }
            if { ([variant_exists ${variant_name}] && [variant_isset ${variant_name}]) || [llength ${conflict_list}]==0 } {
                set any_sql                 yes
            }
        }

        if { !${any_sql} } {
            default_variants-append         +[lindex ${sql_variants} 0]
            if { ![variant_isset [lindex ${sql_variants} 0]] } {
                known_fail                  yes
                pre-extract {
                    ui_error                "At least one SQL variant must be selected."
                    return -code error      "No SQL variant selected."
                }
            }
        }

        foreach {variant_name variant_info} ${sql_variants} {
            if { ([variant_exists ${variant_name}] && [variant_isset ${variant_name}]) || [llength ${conflict_list}]==0 } {
                depends_lib-append          {*}[lindex ${variant_info} 0]
                configure.post_args-append  {*}[subst [lindex ${variant_info} 1]]
            }
        }

        post-destroot {
            if {[file exists ${qt6.dir}/sbom/qsqlitedriverplugins-${version}.spdx]} {
                file delete ${destroot}${qt6.dir}/sbom/qsqlitedriverplugins-${version}.spdx
            }
        }
    notes "${destroot}${qt6.dir}/sbom/qsqlitedriverplugins-${version}.spdx"
    }
}

###############################################################################
# Special Cases
###############################################################################
subport ${name}-qttools {
    configure.env-append            LLVM_INSTALL_DIR=${prefix}/libexec/llvm-${llvm_version}

    post-destroot {
        # avoid having to add `-Wl,-rpath ${prefix}/libexec/llvm-${llvm_version}/lib` or something like it
        foreach bin {lupdate} {
            foreach lib {libclang.dylib libclang-cpp.dylib libLLVM.dylib} {
                system              "install_name_tool -change @rpath/${lib} ${prefix}/libexec/llvm-${llvm_version}/lib/${lib} ${destroot}${qt6.dir}/bin/${bin}"
            }
        }
    }
}

if { ${subport} in [list "${name}-qtwebengine" "${name}-qtwebengine-docs"] } {
    compiler.cxx_standard           2020
    compiler.blacklist-append       {clang < 1700}

    configure.env-append            PYTHON3_PATH=${frameworks_dir}/Python.framework/Versions/${python_branch}/bin

    # in ${worksrcpath}, `${qt6.dir}/bin/qt-configure-module . -help` and `${qt6.dir}/bin/qt-configure-module . -list-features`
    # it is not clear why, but icu and ffmpeg support must be added manually
    # native-spellchecker support is off by default
    # support for proprietary codecs could by added via `-webengine-proprietary-codecs`
    configure.args-append           -webengine-icu \
                                    -webengine-ffmpeg \
                                    -webengine-native-spellchecker

    # attempt to limit the resources for building QtWebEngine
    # see: https://trac.macports.org/ticket/73057
    build.mem_per_job               2048
    build.env-append                NINJAJOBS=${build.jobs} \
                                    NINJAFLAGS=-j${build.jobs}

    # avoid
    #     xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer
    #     directory '/Library/Developer/CommandLineTools' is a command line tools
    #     instance
    use_xcode                       yes

    # Fix build with Xcode 26, metal and metallib have moved
    # see: https://trac.macports.org/ticket/73037
    patchfiles-append               patch-qtwebengine-metal-toolchain.diff
}

subport ${name}-qtwebengine {
    # manually install icudtl.dat
    post-destroot {
        xinstall -m 0644 ${worksrcpath}/src/3rdparty/chromium/third_party/icu/common/icudtl.dat \
                         ${destroot}${qt6.dir}/lib/QtWebEngineCore.framework/Resources/
    }
}

subport ${name}-qtmultimedia {
    # GStreamer will be found if gstreamer1 and gstreamer1-gst-plugins-base are installed
    # however, an error will ensue since the GStreamer support requires "Linux DMA buffer support"
    # see
    #     https://code.qt.io/cgit/qt/qtmultimedia.git/tree/src/plugins/multimedia/gstreamer/CMakeLists.txt
    #     https://code.qt.io/cgit/qt/qtmultimedia.git/tree/src/multimedia/configure.cmake
    configure.args-append           -no-gstreamer

    configure.post_args-append      -DFFMPEG_DIR=${prefix}/libexec/ffmpeg8 \
                                    -DAVCODEC_INCLUDE_DIR=${prefix}/libexec/ffmpeg8/include \
                                    -DAVCODEC_LIBRARY=${prefix}/libexec/ffmpeg8/lib/libavcodec.dylib \
                                    -DAVFORMAT_INCLUDE_DIR=${prefix}/libexec/ffmpeg8/include \
                                    -DAVFORMAT_LIBRARY=${prefix}/libexec/ffmpeg8/lib/libavformat.dylib \
                                    -DAVUTIL_INCLUDE_DIR=${prefix}/libexec/ffmpeg8/include\
                                    -DAVUTIL_LIBRARY=${prefix}/libexec/ffmpeg8/lib/libavutil.dylib
}

subport ${name}-qt5compat {
    patchfiles-append               patch-qt5compat-find_libs.diff
}

subport ${name}-qtspeech {
    # ALSA is Linux only (https://www.alsa-project.org/wiki/Main_Page)
    # Speech Dispatcher *might* be made to work on macOS (https://freebsoft.org/speechd)
    configure.args-append           -no-flite \
                                    -no-speechd
}

if { ${subport} eq "${name}-qtbase" || ${subport} eq "${name}-qtbase-docs" } {

    configure.pre_args-replace      --prefix=${prefix} \
                                    "-prefix ${qt6.dir}"

    # configure options:
    configure.args-append           -shared \
                                    -accessibility

    # SQL Options
    foreach driver {db2 ibase mysql oci odbc psql sqlite} {
        configure.args-append       -no-sql-${driver}
    }

    # use -Oz instead of -O2
    configure.args-append           -optimize-size

    configure.args-append           -pkg-config

    # Third Party Libraries:
    configure.args-append           -system-zlib \
                                    -no-mtdev \
                                    -no-journald \
                                    -no-syslog \
                                    -system-libpng \
                                    -system-libjpeg \
                                    -system-freetype \
                                    -system-harfbuzz \
                                    -system-pcre \
                                    -system-doubleconversion \
                                    -no-openssl \
                                    -no-libproxy \
                                    -glib \
                                    -no-gtk

    # additional options:
    configure.args-append           {-nomake examples} \
                                    {-nomake tests} \
                                    -gui \
                                    -widgets \
                                    -cups \
                                    -no-evdev \
                                    -no-tslib \
                                    -icu \
                                    -no-fontconfig \
                                    -no-pch \
                                    -no-ltcg \
                                    -dbus-linked \
                                    -no-use-gold-linker \
                                    -no-separate-debug-info \
                                    -no-xcb \
                                    -no-eglfs \
                                    -no-gbm \
                                    -no-directfb \
                                    -no-linuxfb \
                                    -no-kms \
                                    -no-libinput \
                                    -no-system-proxies \
                                    -no-libudev \
                                    -no-egl

    # macOS/iOS options:
    configure.args-append           -framework \
                                    -securetransport

    # do not opportunistically enable Vulkan support
    # (TODO: is Vulkan support desirable?)
    # see https://trac.macports.org/ticket/62104
    configure.args-append           -no-feature-vulkan

    # attempt to avoid @rpath
    configure.args-append           -no-rpath \
                                    -no-feature-relocatable
}

subport ${name}-qtbase {
    # this subport uses configure script
    PortGroup                       openssl 1.0

    build.cmd                       ninja
    build.post_args-append          -v
    destroot.target                 install

    variant tests description {Enable tests} {
        configure.args-replace      {-nomake tests} \
                                    {-make tests}
    }

    variant examples description {Build examples} {
        configure.args-replace      {-nomake examples} \
                                    {-make examples}
    }

    variant debug description {Build both release and debug libraries} {
        configure.args-replace      -release \
                                    -debug-and-release
    }

    variant openssl description {Use OpenSSL instead of Secure Transport} {
        configure.args-delete       -securetransport \
                                    -no-openssl
        configure.args-append       -openssl-linked

        # configure has issues locating openssl files
        configure.pre_args-append   -DOPENSSL_ROOT_DIR=[openssl::install_area] \
                                    -DOPENSSL_INCLUDE_DIR=[openssl::include_dir] \
                                    -DOPENSSL_LIBRARIES=[openssl::install_area]/lib \
                                    -DOPENSSL_LIBS='-L[openssl::install_area]/lib -lssl -lcrypto'
    }
    default_variants-append         +openssl

    post-destroot {
        # do not record  __qt_initial_c_compiler and __qt_initial_cxx_compiler
        reinplace                   "s|${configure.cc}|/usr/bin/clang|g" \
                                    ${destroot}${qt6.dir}/lib/cmake/Qt6/qt.toolchain.cmake
        reinplace                   "s|${configure.cxx}|/usr/bin/clang++|g" \
                                    ${destroot}${qt6.dir}/lib/cmake/Qt6/qt.toolchain.cmake

        # return to default value of CMAKE_OSX_DEPLOYMENT_TARGET
        #reinplace                   "s|CMAKE_OSX_DEPLOYMENT_TARGET \"${macosx_deployment_target}\"|CMAKE_OSX_DEPLOYMENT_TARGET \"10.14\"|g" \
        #                            ${destroot}${qt6.dir}/lib/cmake/Qt6/qt.toolchain.cmake

        # do not record QT_SOURCE_TREE
        reinplace                   "s|${worksrcpath}|${qt6.dir}/src|g" \
                                    ${destroot}${qt6.dir}/lib/cmake/Qt6BuildInternals/QtBuildInternalsExtra.cmake

        # do not record original_cmake_path
        reinplace                   "s|${prefix}/bin/cmake|/Applications/CMake.app/Contents/bin/cmake|g" \
                                    ${destroot}${qt6.dir}/bin/qt-cmake
        reinplace                   "s|${prefix}/bin/cmake|/Applications/CMake.app/Contents/bin/cmake|g" \
                                    ${destroot}${qt6.dir}/bin/qt-cmake-create

        if { "${qt6.dir}" ne "${prefix}" } {
            # Add dummy cmake find modules that forward to the real ones
            file mkdir "${destroot}${prefix}/lib/cmake/Qt6"
            foreach configfile [list "Qt6Config.cmake" "Qt6ConfigVersion.cmake"] {
                set fd [open "${destroot}${prefix}/lib/cmake/Qt6/${configfile}" "w"]
                puts $fd "set(_PREFIX_PATH_BAK \${CMAKE_PREFIX_PATH})"
                puts $fd "list(APPEND CMAKE_PREFIX_PATH \"${qt6.dir}\")"
                puts $fd "include(\"${qt6.dir}/lib/cmake/Qt6/${configfile}\")"
                puts $fd "set(CMAKE_PREFIX_PATH \${_PREFIX_PATH_BAK})"
                close $fd
            }
        }
    }

    # Qt builds part of the system using environment provided by MacPorts.
    # It builds the rest using its own internal environment.
    # For consistency, clear MacPorts environment.
    configure.cxx_stdlib
    proc portconfigure::should_add_stdlib {} { return false }
    configure.sdkroot
    configure.cc_archflags
    configure.cxx_archflags
    configure.objc_archflags
    configure.objcxx_archflags
    configure.ld_archflags
    configure.cppflags
    configure.cflags
    configure.cxxflags
    configure.objcflags
    configure.objcxxflags
    configure.ldflags
    configure.pipe                  no
    configure.march
    configure.mtune
    configure.universal_ldflags
    configure.universal_cflags
    configure.universal_cxxflags
    configure.universal_cppflags
}

subport ${name}-qtbase-docs {
    # see https://wiki.qt.io/Building_Qt_Documentation
    build.cmd                      cmake --build ${build.dir}
    destroot.target
    build.target                   --target docs
    destroot.cmd                   cmake --build ${build.dir} --target install_docs
}

###############################################################################
# Applies to allmost all modules
###############################################################################
if { ${subport} ne "${name}" && ${subport} ne "${name}-qtbase" && ${subport} ne "${name}-qtbase-docs" } {
    # attempting to match module configure instructions from here: https://www.qt.io/blog/qt-6-build-system
    configure.cmd                   ${qt6.dir}/bin/qt-configure-module
    configure.dir                   ${workpath}/build
    configure.pre_args              ${worksrcpath}
    configure.args-append           -verbose

    build.dir                       ${workpath}/build
    build.cmd                       cmake --build ${build.dir}

    destroot.target

    if { [lindex [split ${subport} -] end] ne "docs" } {
        build.target
        destroot.cmd               cmake --install ${build.dir}
    } else {
        build.target               --target docs
        destroot.cmd               cmake --build ${build.dir} --target install_docs
    }

    if { [variant_exists examples] } {
        configure.post_args-append  -DQT_BUILD_EXAMPLES=[expr {[variant_isset examples] ? ON : OFF}]
    }
    if { [variant_exists tests] } {
        configure.post_args-append  -DQT_BUILD_TESTS=[expr {[variant_isset tests] ? ON : OFF}]
    }
}

###############################################################################
# Applies to all subports except ${name}
#     this code may depend on the subport specific code (e.g., configure.cc)
###############################################################################
depends_build-append                path:bin/cmake:cmake \
                                    port:ninja \
                                    port:pkgconfig

# because CPATH is set, pkgconfig does not include ${prefix}/lib and ${prefix}/include even when requested
# this means that files in ${prefix}/lib and ${prefix}/include are the *last* to be found
# this causes problems when there are files in ${worksrpath} that are unintentionally found instead
configure.env-append                PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 \
                                    PKG_CONFIG_ALLOW_SYSTEM_LIBS=1
build.env-append                    PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 \
                                    PKG_CONFIG_ALLOW_SYSTEM_LIBS=1

configure.universal_args

test.cmd                            ctest
test.args                           -V
test.target

# ninja needs the DESTDIR argument in the environment
destroot.destdir
destroot.env-append                 DESTDIR=${destroot}

# set CMake variables (similar to what cmake PortGroup does)
# to allow using ccache and controlling compiler selection
configure.post_args-prepend         --
configure.post_args-append          -DCMAKE_C_COMPILER=[option configure.cc] \
                                    -DCMAKE_CXX_COMPILER=[option configure.cxx] \
                                    -DCMAKE_OBJC_COMPILER=[option configure.objc] \
                                    -DCMAKE_OBJCXX_COMPILER=[option configure.objcxx] \
                                    -DCMAKE_OSX_DEPLOYMENT_TARGET=${macosx_deployment_target}
if { ${configure.ccache} } {
    if { ${subport} ne "${name}-qtbase" } {
        configure.post_args-append  -DQT_USE_CCACHE=ON
    } else {
        # do not use `configure.args-append -ccache`
        # or `configure.post_args-append -DQT_USE_CCACHE=1`
        # since that affects installed files.
        configure.post_args-append  -DCMAKE_C_COMPILER_LAUNCHER=${prefix}/bin/ccache \
                                    -DCMAKE_CXX_COMPILER_LAUNCHER=${prefix}/bin/ccache \
                                    -DCMAKE_OBJC_COMPILER_LAUNCHER=${prefix}/bin/ccache \
                                    -DCMAKE_OBJCXX_COMPILER_LAUNCHER=${prefix}/bin/ccache
    }
}

test.run                            [expr {[variant_exists tests] && [variant_isset tests] ? yes : no}]

if { ${universal_possible} && [variant_isset universal] } {
    configure.post_args-append      -DCMAKE_OSX_ARCHITECTURES="[join ${configure.universal_archs} \;]"
} elseif { ${configure.build_arch} ne ""  } {
    configure.post_args-append      -DCMAKE_OSX_ARCHITECTURES="${configure.build_arch}"
}

# attempt to avoid @rpath
configure.post_args-append          -DCMAKE_INSTALL_NAME_DIR=${qt6.dir}/lib

post-destroot {
    fs-traverse f ${destroot} {
        if { [file isfile ${f}] && [file extension ${f}] eq ".prl" } {
            # do not record build directory
            reinplace -q            "/^QMAKE_PRL_BUILD_DIR = /d" \
                                    ${f}
        }
    }

    # .app and non-.app programs are both put in ${qt6.dir}/bin
    # put a link of any .app programs in the ${applications_dir}/Qt6
    xinstall -d -m 0755             ${destroot}${applications_dir}/Qt6
    foreach app [glob -nocomplain -tails -directory ${destroot}${qt6.dir}/bin *.app] {
        ln -s                       ${qt6.dir}/bin/${app} \
                                    ${destroot}${applications_dir}/Qt6
    }
}

livecheck.type                      none

###############################################################################
# Special Case: must be near the end since it undoes other code
###############################################################################
subport ${name} {
    # the main port is Meta-port to install various modules
    revision                        0

    description                     Qt Tool Kit ${qt_major}
    long_description                Qt Tool Kit: A cross-platform framework \
                                    (headers, data, and libraries) for writing \
                                    cross-platform GUI-based applications.

    master_sites
    distfiles
    use_configure                   no
    supported_archs                 noarch
    platforms                       any
    installs_libs                   no
    test.run                        no
    depends_extract
    depends_build
    depends_lib
    depends_test

    build                           {}

    # create a dummy file so the port can be successfully activated
    destroot {
        xinstall -d -m 0755         ${destroot}${prefix}/share/doc/${subport}
        set docfile                 [open ${destroot}${prefix}/share/doc/${subport}/README.txt "w"]
        puts ${docfile}             "Meta-port for ${name}"
        puts ${docfile}             "${long_description}"
        close ${docfile}
    }

    foreach {module module_info} [array get modules] {
        if { [lindex ${module_info} 5] eq "" } {
            depends_run-append      port:${name}-${module}
        }
    }
    depends_run-append              port:${name}-sqlite-plugin

    livecheck.type                  regex
    livecheck.url                   https://download.qt.io/archive/qt/${branch}/
    livecheck.regex                 (\\d+(\\.\\d+)\\.\\d+)
}
