# -*- 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.1
PortGroup           github 1.0
PortGroup           wxWidgets 1.0

name                CubicSDR
categories          science comms
platforms           darwin macosx
license             GPL-2
maintainers         {ra1nb0w @ra1nb0w} {michaelld @michaelld} openmaintainer
description         Cross-Platform Software-Defined Radio Application
long_description    CubicSDR is the software portion of Software Defined \
    Radio. By Using hardware that converts RF spectrum into a digital \
    stream we are able to build complex radios to do many types of \
    functions in software instead of traditional hardwre.
homepage            https://www.cubicsdr.com

github.setup        cjcliffe CubicSDR 071204f3928919949bab572bde5231e1dbd1cb29
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
version             20230114-[string range ${github.version} 0 7]
checksums           rmd160  0e9d4a1c34be596c3cef1bb1cc3701d852fd31d7 \
                    sha256  90001897218ab72bc109ea4e4a7cd8ea2063d0682b6abe610b8f58405cefb50b \
                    size    37609809
revision            0

compiler.cxx_standard 2011

# CubicSDR requires wxWidgets.use of wxWidgets-3.1 or newer -- "3.2"
# by the wxWidgets PG -- which is what this provides. selecting 3.0
# does not work.
wxWidgets.use       wxWidgets-3.2

depends_lib-append \
    port:liquid-dsp \
    port:${wxWidgets.port} \
    port:SoapySDR

configure.args-append \
    -DCMAKE_BUILD_TYPE=Release \
    -DwxWidgets_CONFIG_EXECUTABLE=${wxWidgets.wxconfig}

configure.cxxflags-append \
    -D_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_

variant hamlib description {Support hamlib for radio control functions} {
    depends_lib-append      path:lib/libhamlib.dylib:hamlib
    configure.args-append   -DUSE_HAMLIB=1
}

variant bundle description {Enable the optional macOS bundle of CubicSDR} {
    configure.args-append   -DBUNDLE_APP=1 \
        -DCPACK_BINARY_DRAGNDROP=0

    # avoid cpack
    destroot {}

    post-destroot {
        xinstall -d -m 0755 ${destroot}${applications_dir}
        copy ${workpath}/build/x64/CubicSDR.app ${destroot}${applications_dir}
    }
}

default_variants-append +bundle

# the readme -recommends- OSX 10.9 or later, but this is not really
# required. Tweaking the top-level CMakeLists.txt to remove
# constraints allows building at least back to OSX 10.7. Removing
# these is also good practice since there are conflicts between what
# macPorts provides (e.g., in CXXFLAGS) and what CubicSDR is trying to
# set internal to the build.
patchfiles-append patch-fix-build-older-osx.diff

# CubicSDR requires wxWidgets.use of wxWidgets-3.1 or newer -- "3.2"
# by the wxWidgets PG -- and the wxWidgets 3.2 options do not build on
# older than OSX 10.7, so this is a solid requirement.
if {${os.platform} eq "darwin" && ${os.major} < 11} {
    pre-fetch {
        ui_error "${subport} @${version} requires OS X 10.7 or newer"
        return -code error "unsupported Mac OS X version"
    }
}
