# -*- 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

name                        ccls
github.setup                MaskRay ccls 0.20241108
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from         tarball
revision                    1

categories                  devel
license                     Apache-2
maintainers                 {egorenar @egorenar} {mascguy @mascguy} openmaintainer

description                 C/C++/ObjC language server supporting cross references,\
                            hierarchies, completion and semantic highlighting
long_description            {*}${description}

checksums                   rmd160  429cb92844a62fb83385db30e129aa5a36c0d262 \
                            sha256  28c2013c39dd9f20d13dc933d105677bfa9332036bca44282a5fbd42dd986a3e \
                            size    161123

set ccls_default            ccls-clang-10
set select_path             ${filespath}/portselect

subport ccls_select {
    PortGroup               select 1.0
    PortGroup               stub 1.0

    supported_archs         noarch
    platforms               any

    post-destroot {
        select::install ${name} ${select_path}/base
        select::install ${name} ${select_path}/none
    }
}

foreach clang_v {10 11 12 13 14} {
    subport ccls-clang-${clang_v} {
        PortGroup             cmake 1.1
        PortGroup             legacysupport 1.1
        PortGroup             select 1.0

        select.group          ${name}
        select.file           ${select_path}/${subport}

        legacysupport.newest_darwin_requires_legacy \
                              15
        legacysupport.use_mp_libcxx \
                              yes

        compiler.whitelist    macports-clang-${clang_v}
        compiler.cxx_standard 2017
        cmake.set_cxx_standard yes

        # Reduce compilation warnings
        configure.cppflags-append \
                              -Wno-deprecated-declarations

        cmake.prefix_path-append \
                              ${prefix}/libexec/llvm-${clang_v}

        configure.args-append -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE \
                              -DUSE_SYSTEM_RAPIDJSON=ON \
                              -DCCLS_VERSION="${version}"

        depends_build-append \
                              port:pkgconfig

        depends_lib-append \
                              port:clang-${clang_v} \
                              port:libffi \
                              port:libxml2 \
                              port:ncurses \
                              port:rapidjson \
                              port:zlib

        depends_run-append \
                              port:ccls_select

        post-destroot {
            # Avoid conflicts between different clang builds
            move ${destroot}${prefix}/bin/ccls ${destroot}${prefix}/bin/${subport}
        }
    }
}

if {${subport} eq ${name}} {
    PortGroup               stub 1.0

    supported_archs         noarch
    platforms               any

    description             {*}${description} (meta port)

    depends_lib-append      port:${ccls_default}
} else {
    livecheck.type          none
}
