# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0

PortGroup           cmake 1.0
PortGroup           github 1.0
PortGroup           active_variants 1.1
PortGroup           boost 1.0

name                gnss-sdr
maintainers         {michaelld @michaelld} {gmail.com:carles.fernandez @carlesfernandez} openmaintainer
description         An Open Source Global Navigation Satellite Systems (GNSS) (for example: GPS, Galileo, Glonass, Beidou, etc) Software Defined Radio (SDR) Receiver
categories          science
license             GPL-3
platforms           darwin

dist_subdir         gnss-sdr

compiler.cxx_standard 2014
compiler.thread_local_storage yes
boost.version 1.71

if {${subport} eq "gnss-sdr"} {

    long_description    ${description}: \
        This port is kept up with the GNSS-SDR release, which is typically updated every few months.

    github.setup    gnss-sdr gnss-sdr 0.0.19 v
    revision        1
    checksums       rmd160  11daaaa2e4acbbcc837d8bd4f42546a6440675bc \
                    sha256  e1f555da5ed8d0e0002441b771993409af29ed897784a0ebc7ee8d6c74b0cb98 \
                    size    4086145

    conflicts       gnss-sdr-devel

    depends_lib-append  port:volk-gnss-sdr

}

subport gnss-sdr-devel {
    long_description    ${description}: \
        This port is kept up with the GNSS-SDR GIT next branch, which is typically updated daily to weekly. This version of GNSS-SDR generally contains fixes and new features that will be incorporated in an upcoming release.
    github.setup    gnss-sdr gnss-sdr ec180d852574e10c621f9bf498d3ef70d26342ce
    version         20240126-[string range ${github.version} 0 7]
    checksums       rmd160  6171d3966487f1cdf78fcc18e9a3f33f7a6f87a4 \
                    sha256  6fbf9bfa1813a00daefdaa5a11b3f15f396af4c957b1792378e4f2a92952723a \
                    size    4086092
    revision        1

    conflicts       gnss-sdr

    depends_lib-append port:volk-gnss-sdr-devel

    # specify version info

    configure.args-append \
        -DGIT_BRANCH="devel-MacPorts" \
        -DGIT_COMMIT_HASH="${version}"

    # overload the github livecheck branch

    github.livecheck.branch next

}

# override github PortGroup homepage setting

homepage            https://gnss-sdr.org

depends_build-append \
    port:pkgconfig

depends_lib-append  \
    port:armadillo \
    port:google-glog \
    port:matio \
    port:protobuf3-cpp \
    port:pugixml \
    path:lib/libgnuradio-runtime.dylib:gnuradio \
    path:lib/libuhd.dylib:uhd \
    path:lib/pkgconfig/gnutls.pc:gnutls

# Since Sonoma, gnss-sdr makes use of the Accelerate
# framework instead of the lapack port. If that port
# is already installed, it will be ignored.
if {${os.platform} eq "darwin" && ${os.major} <= 22} {
    depends_lib-append  \
        port:lapack
}

depends_test-append \
    port:cppunit


if {[catch {set installed [lindex [registry_active gnuradio] 1]}]} {

    require_active_variants port:gnuradio uhd

}

if {[catch {set installed [lindex [registry_active gnuradio-devel] 1]}]} {

    require_active_variants port:gnuradio-devel uhd

}

if {[catch {set installed [lindex [registry_active gnuradio-next] 1]}]} {

    require_active_variants port:gnuradio-next uhd

}


test.run yes
test.target run_tests

# require specific variants

require_active_variants port:google-glog gflags

# do VPATH (out of source tree) build

cmake.out_of_source yes

# remove top-level library path, such that internal libraries are used
# instead of any already-installed ones.

configure.ldflags-delete -L${prefix}/lib

configure.args-append \
    -DENABLE_PACKAGING=OFF \
    -DENABLE_OWN_GLOG=OFF \
    -DENABLE_GENERIC_ARCH=OFF \
    -DENABLE_UNIT_TESTING_MINIMAL=ON

# specify dependency arguments

configure.args-append \
    -DARMADILLO_INCLUDE_DIR=${prefix}/include \
    -DARMADILLO_LIBRARY=${prefix}/lib/libarmadillo.dylib \
    -DGLOG_INCLUDE_DIR=${prefix}/include/glog \
    -DGLOG_LIBRARY=${prefix}/lib/libglog.dylib \
    -DGNUTLS_INCLUDE_DIR=${prefix}/include \
    -DGNUTLS_LIBRARY=${prefix}/lib/libgnutls.dylib \
    -DGNUTLS_OPENSSL_LIBRARY=${prefix}/lib/libgnutls-openssl.dylib \
    -DMATIO_INCLUDE_DIR=${prefix}/include \
    -DMATIO_LIBRARY=${prefix}/lib/libmatio.dylib \
    -DPUGIXML_INCLUDE_DIR=${prefix}/include \
    -DPUGIXML_LIBRARY=${prefix}/lib/libpugixml.dylib \
    -DUHD_INCLUDE_DIR=${prefix}/include \
    -DUHD_LIBRARIES=${prefix}/lib/libuhd.dylib \
    -DVOLK_GNSSSDR_INCLUDE_DIR=${prefix}/include \
    -DVOLK_GNSSSDR_LIBRARIES=${prefix}/lib/libvolk_gnsssdr.dylib


# enable default variants: all except +docs, +debug, and +universal
# do not enable +docs because it requires a non-standard variant for doxygen.

default_variants +opencl

variant docs description "Install ${name} documentation" {

    depends_build-append \
        path:bin/doxygen:doxygen

    # for wasysym.sty

    depends_build-append \
        port:texlive-fonts-recommended

    # require specific variant

    require_active_variants path:bin/doxygen:doxygen docs

    configure.args-append \
        -DDOXYGEN_EXECUTABLE=${prefix}/bin/doxygen

    # extra targets

    build.target-append doc pdfmanual

}

if {![variant_isset docs]} {

    configure.args-append \
        -DDOXYGEN_EXECUTABLE=

}

variant opencl description "Install ${name} with support for building of processing blocks implemented with OpenCL (experimental)" {

    configure.args-append \
        -DENABLE_OPENCL=ON

}

if {![variant_isset opencl]} {

    configure.args-append \
        -DENABLE_OPENCL=OFF

}

variant osmosdr description "Install ${name} with support for OsmoSDR and other front-ends (RTL-based dongles, HackRF, bladeRF, etc.) as signal source." {

    depends_build-append \
        port:gr-osmosdr

    configure.args-append \
        -DENABLE_OSMOSDR=ON

}

if {![variant_isset osmosdr]} {

    configure.args-append \
        -DENABLE_OSMOSDR=OFF

}

variant array description "Install ${name} with support for CTTC's antenna array front-end as signal source (experimental)" {

    configure.args-append \
        -DENABLE_ARRAY=ON

}

if {![variant_isset array]} {

    configure.args-append \
        -DENABLE_ARRAY=OFF

}
