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

name                  SDRangel
platforms             darwin macosx
categories            science
license               GPL-3
maintainers           {ra1nb0w @ra1nb0w} {michaelld @michaelld} openmaintainer

description           SDRangel is an Open Source Qt5 / OpenGL 3.0+ SDR \
    and signal analyzer frontend to various hardware.
long_description    {*}${description}

github.setup          f4exb sdrangel 7.25.1 v
github.tarball_from   archive
checksums             rmd160  3ba9e39ee3050360b0637ddf9fdf4306aab10149 \
                      sha256  13a2364ba8985f4f02a6e1b8d38a576adc7c527b9d71184031bd2355ac4b5673 \
                      size    137464626
revision              1

# check just the version 7 branch for now
github.livecheck.regex (7\[0-9.]*)

# not linked directly to openssl
license_noconflict-append \
    openssl \
    openssl11

compiler.c_standard   2011
compiler.cxx_standard 2017

# disable because macOS < 10.12 since it has a too old Qt version
if {${os.platform} eq "darwin" && ${os.major} <= 16} {
    known_fail yes
    pre-fetch {
        ui_error "${name} @${version} requires Mac OS X 10.13 or later"
        return -code error "Unsupported Mac OS X version"
    }
}

boost.version         1.88
boost.depends_type    build

set opencv_ver        4

depends_lib-append \
    port:aptdec \
    port:cm256cc \
    port:codec2 \
    port:dab-cmdline \
    port:dsdcc \
    path:lib/libavcodec.dylib:ffmpeg \
    port:fftw-3-single \
    port:flac \
    port:libopus \
    port:libsigmf \
    path:lib/pkgconfig/libusb-1.0.pc:libusb \
    port:mbelib \
    path:lib/opencv${opencv_ver}/libopencv_core.dylib:opencv${opencv_ver} \
    port:serialDV \
    port:sgp4 \
    port:zlib

qt5.depends_build_component \
    qttools

qt5.depends_component \
    qtcharts \
    qtdeclarative \
    qtgamepad \
    qtlocation \
    qtmultimedia \
    qtserialport \
    qtspeech \
    qtsvg \
    qtwebchannel \
    qtwebengine \
    qtwebsockets

patchfiles \
    find-flac.patch

post-patch {
    reinplace "s|FLAC_LIBRARIES|FLAC_LIBRARY|g" \
        ${worksrcpath}/plugins/samplesource/remotetcpinput/CMakeLists.txt \
        ${worksrcpath}/plugins/channelrx/remotetcpsink/CMakeLists.txt
}

cmake.prefix_path-append \
    ${prefix}/libexec/opencv${opencv_ver}

# Use OpenGL framework instead of mesa
configure.pre_args-delete   -DCMAKE_FIND_FRAMEWORK=LAST

configure.args-append \
    -DBUILD_GUI=OFF \
    -DBUILD_SERVER=OFF \
    -DBUNDLE=OFF \
    -DENABLE_AIRSPY=OFF \
    -DENABLE_AIRSPYHF=OFF \
    -DENABLE_BLADERF=OFF \
    -DENABLE_FUNCUBE=OFF \
    -DENABLE_HACKRF=OFF \
    -DENABLE_IIO=OFF \
    -DENABLE_LIMESUITE=OFF \
    -DENABLE_MIRISDR=OFF \
    -DENABLE_PERSEUS=OFF \
    -DENABLE_RTLSDR=OFF \
    -DENABLE_SOAPYSDR=OFF \
    -DENABLE_SDRPLAY=OFF \
    -DENABLE_XTRX=OFF \
    -DARCH_OPT= \
    -DRX_SAMPLE_24BIT=ON \
    -DENABLE_CHANNELTX_REMOTESOURCE=OFF

variant debug description {Enable debug messages} {
    configure.args-append   \
        -DCMAKE_BUILD_TYPE=Debug \
        -DDEBUG_OUTPUT=ON
}

variant gui description {Enable Gui} {
    configure.args-replace  -DBUILD_GUI=OFF -DBUILD_GUI=ON

    app.create yes
    app.name SDRangel
    app.executable sdrangel
    app.icon cmake/cpack/sdrangel_icon.icns
    app.retina yes
}

variant native description {Enable native cpu flags (recommended)} {
    configure.args-replace  -DARCH_OPT= -DARCH_OPT=native
}

variant server description {Enable server binary} {
    configure.args-replace  -DBUILD_SERVER=OFF -DBUILD_SERVER=ON
}

variant airspy description {Enable Airspy hardware} {
    depends_lib-append      port:airspy
    configure.args-replace  -DENABLE_AIRSPY=OFF -DENABLE_AIRSPY=ON
}

variant airspyhf description {Enable AirspyHF hardware} {
    depends_lib-append      port:airspyhf
    configure.args-replace  -DENABLE_AIRSPYHF=OFF -DENABLE_AIRSPYHF=ON
}

variant bladerf description {Enable bladeRF hardware} {
    depends_lib-append      port:bladeRF
    configure.args-replace  -DENABLE_BLADERF=OFF -DENABLE_BLADERF=ON
}

variant funcube description {Enable funcube hardware} {
    configure.args-replace  -DENABLE_FUNCUBE=OFF -DENABLE_FUNCUBE=ON
}

variant hackrf description {Enable HackRF hardware} {
    depends_lib-append      path:lib/libhackrf.dylib:hackrf
    configure.args-replace  -DENABLE_HACKRF=OFF -DENABLE_HACKRF=ON
}

variant libiio description {Enable libiio support, like PlutoSDR hardware} {
    depends_lib-append      port:libiio
    configure.args-replace  -DENABLE_IIO=OFF -DENABLE_IIO=ON
}

variant limesuite description {Enable limesuite hardware} {
    depends_lib-append      path:lib/libLimeSuite.dylib:limesuite
    configure.args-replace  -DENABLE_LIMESUITE=OFF -DENABLE_LIMESUITE=ON
}

variant perseus description {Enable perseus sdr device} {
    depends_lib-append      port:perseus-sdr
    configure.args-replace  -DENABLE_PERSEUS=OFF -DENABLE_PERSEUS=ON
}

variant rtlsdr description {Enable rtl-sdr hardware} {
    depends_lib-append      port:rtl-sdr
    configure.args-replace  -DENABLE_RTLSDR=OFF -DENABLE_RTLSDR=ON
}

variant xtrx description {Enable xtrx hardware} {
    configure.args-replace  -DENABLE_XTRX=OFF -DENABLE_XTRX=ON
}

variant soapysdr description {Enable SoapySDR support} {
    depends_lib-append      port:SoapySDR
    configure.args-replace  -DENABLE_SOAPYSDR=OFF -DENABLE_SOAPYSDR=ON
    configure.args-append   -DSOAPYSDR_DIR=${prefix}
}

variant sdrplay description {Enable SDRplay support} {
    depends_lib-append      port:SDRplay3
    configure.args-replace  -DENABLE_SDRPLAY=OFF -DENABLE_SDRPLAY=ON
}

default_variants +soapysdr +airspy +airspyhf +limesuite +rtlsdr +funcube +server +gui

test.run     yes
test.cmd     ./sdrangelbench
