# -*- 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           cmake 1.1
PortGroup           github 1.0

github.setup        CastXML CastXML 0.6.13 v
github.tarball_from archive

name                castxml
epoch               20190718
revision            1
categories          lang
license             Apache-2

maintainers         {stromnov @stromnov} openmaintainer

description         CastXML is a C-family abstract syntax tree XML output tool.
long_description    {*}${description}

checksums           rmd160  e6ac6f251a778ebefb5049b1224a1d47877b3e5a \
                    sha256  df954886464fe624887411e5f4e2a7db00da3d64a48f142d3aff973e2097e2d6 \
                    size    123554

# See: https://trac.macports.org/ticket/68235
compiler.blacklist-append \
                    {clang < 900}

compiler.cxx_standard \
                    2017

depends_lib-append \
                    port:libedit \
                    port:libffi \
                    port:libxml2 \
                    port:ncurses \
                    port:zlib \
                    port:zstd

configure.args-append \
                    -DCastXML_INSTALL_DOC_DIR=share/doc/castxml

# List of clang versions to offer variants for
set clang_vers { 6.0 7.0 8.0 9.0 10 11 12 13 14 15 16 17 18 19 20 21 }

proc variant_name {ver} {
    return clang[string map {. {}} ${ver}]
}

# build list of all clang variant names
set clang_variants {}
foreach ver ${clang_vers} { lappend clang_variants [variant_name $ver] }

proc build_conflicts {v} {
    global clang_variants
    set i [lsearch -exact ${clang_variants} ${v}]
    return [lreplace ${clang_variants} ${i} ${i}]
}

set has_variant no
foreach ver ${clang_vers} {
    set v_name [variant_name ${ver}]
    set c [build_conflicts ${v_name}]
    variant ${v_name} conflicts {*}${c} description "Use clang ${ver} toolchain" { }
    if {[variant_isset ${v_name}]} {
        set has_variant yes
    }
}
if {!$has_variant} { default_variants +clang21 }

foreach ver ${clang_vers} {
    set v_name [variant_name ${ver}]
    if {[variant_isset ${v_name}]} {
        depends_lib-append          port:llvm-${ver} \
                                    port:clang-${ver}
        configure.args-append       -DLLVM_DIR=${prefix}/libexec/llvm-${ver}/lib/cmake/llvm
        cmake.install_rpath-append  ${prefix}/libexec/llvm-${ver}/lib
    }
}
