# -*- 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.13.0 v
checksums             rmd160  4125429eb915724c0662b1db2078eb3a58fd988e \
                      sha256  a8dd0ebcbf6e608382b9b46471e80baf5f5b73b2063c2e49502b6bb3fac5163b \
                      size    79627129
revision              0

# 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
# error: call to 'abs' is ambiguous
#   float dec = std::abs(degrees) + minutes * 1.0f/60.0f + seconds * 1.0f/(60.0f*60.0f);
# std::abs was only introduced in c++17 so whilst the port claims to only
# require c++14 it actually needs c++17
compiler.cxx_standard 2017

# use C++17 for the build itself
patchfiles-append     use-cxx17.patch

# 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"
    }
}

set opencv_ver        3

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

qt5.depends_component \
    qtmultimedia \
    qttools \
    qtwebsockets \
    qtlocation \
    qtcharts \
    qtspeech \
    qtwebengine

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 \
    -DFORCE_SSE41=ON \
    -DIconv_LIBRARY=${prefix}/lib/libiconv.dylib \
    -DIconv_INCLUDE_DIR=${prefix}/include \
    -DRX_SAMPLE_24BIT=ON \
    -DENABLE_CHANNELTX_REMOTESOURCE=OFF

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

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  -DFORCE_SSE41=ON -DFORCE_SSE41=OFF
}

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
