cartr / homebrew-qt4

Homebrew tap for Qt4 and dependent formulae on Sierra
BSD 2-Clause "Simplified" License
105 stars 42 forks source link

Add GNURadio to this tap? #52

Open shafdog opened 6 years ago

shafdog commented 6 years ago

The GNURadio package/recipe in the core Brew doesn't include QT support. GNURadio has a GUI builder tool that let you build controls to use a software defined radio (SDR) called gnuradio-companion. But the recipe in the mainline brew doesn't build with QT, likely since as best I can tell GNURadio doesn't work with Qt5. Without QT, many examples don't work and the WX widgets are more limited than QT ones in GNURadio. So while the homebrew-core version does "works", it's improvised since apparently GNURadio can't easily be adapted to Qt5.

The GNURadio team recommends MacPorts since it works with all features, but really don't want replace brew and certainly don't want multiple package managers on my Mac. Anyway, found this tap, created a new version of the gnuradio.rb recipe that uses this QT tap & enables QT build option... Seems to build/work, at least for me.

Not sure if it belong here or not, but since it did take quite a bit to figure out...below the alternative gnuradio recipe I used with this tap to get QT working in gnuradio-companion.

Anyway, this works for me:

class GnuradioQt4 < Formula
  desc "SDK providing the signal processing runtime and processing blocks (modified by Ammo)"
  homepage "https://gnuradio.org/"
  url "https://gnuradio.org/releases/gnuradio/gnuradio-3.7.11.tar.gz"
  sha256 "87d9ba3183858efdbb237add3f9de40f7d65f25e16904a9bc8d764a7287252d4"
  revision 4
  head "https://github.com/gnuradio/gnuradio.git"

  bottle do
    sha256 "b7659bc81db490f2f12aac8c08a8687f3b44d4e4c40adb284c32780066f42f3a" => :high_sierra
    sha256 "bb9aa035ea9c23b78830f829741ede4a5592036588fb870b8b42760b38bbfb1c" => :sierra
    sha256 "0d8f3e33186012db38826db7560616c43b18cee8cfbf469d2edb36499e94481d" => :el_capitan
  end

  option "without-python@2", "Build without python support"

  deprecated_option "without-python" => "without-python@2"

  depends_on "cmake" => :build
  depends_on "pkg-config" => :build
  depends_on "python@2"
  depends_on "boost"
  depends_on "fftw"
  depends_on "gsl"
  depends_on "zeromq"

  if build.with? "python@2"
    depends_on "swig" => :build
    depends_on "numpy"
  end

  # For documentation
  depends_on "doxygen" => [:build, :recommended]
  depends_on "sphinx-doc" => [:build, :recommended]

  depends_on "qwt-qt4" => ['with-qwtmathml']
  depends_on "cartr/qt4/pyqt@4"
  depends_on "uhd" => :recommended
  depends_on "sdl" => :recommended
  depends_on "jack" => :optional
  depends_on "portaudio" => :recommended
  depends_on "wxpython" => :recommended
  depends_on "pygtk" => :recommended

  # Upstream PR from 17 Apr 2018 "Boost 1.67.0 compatibility"
  patch do
    url "https://github.com/gnuradio/gnuradio/pull/1733.patch?full_index=1"
    sha256 "f02a04fb179a9b525b5e4ba8171ce5737c16d64f06f0e318ce092c6b4e19025f"
  end

  # cheetah starts here
  resource "Markdown" do
    url "https://files.pythonhosted.org/packages/1d/25/3f6d2cb31ec42ca5bd3bfbea99b63892b735d76e26f20dd2dcc34ffe4f0d/Markdown-2.6.8.tar.gz"
    sha256 "0ac8a81e658167da95d063a9279c9c1b2699f37c7c4153256a458b3a43860e33"
  end

  resource "Cheetah" do
    url "https://files.pythonhosted.org/packages/cd/b0/c2d700252fc251e91c08639ff41a8a5203b627f4e0a2ae18a6b662ab32ea/Cheetah-2.4.4.tar.gz"
    sha256 "be308229f0c1e5e5af4f27d7ee06d90bb19e6af3059794e5fd536a6f29a9b550"
  end
  # cheetah ends here

  resource "lxml" do
    url "https://files.pythonhosted.org/packages/39/e8/a8e0b1fa65dd021d48fe21464f71783655f39a41f218293c1c590d54eb82/lxml-3.7.3.tar.gz"
    sha256 "aa502d78a51ee7d127b4824ff96500f0181d3c7826e6ee7b800d068be79361c7"
  end

  resource "cppzmq" do
    url "https://raw.githubusercontent.com/zeromq/cppzmq/46fc0572c5e9f09a32a23d6f22fd79b841f77e00/zmq.hpp"
    sha256 "964031c0944f913933f55ad1610938105a6657a69d1ac5a6dd50e16a679104d5"
  end

  def install
    ENV.prepend_path "PATH", "/System/Library/Frameworks/Python.framework/Versions/2.7/bin"

    ENV["CHEETAH_INSTALL_WITHOUT_SETUPTOOLS"] = "1"
    ENV["XML_CATALOG_FILES"] = etc/"xml/catalog"
    ENV.prepend_create_path "PYTHONPATH", libexec/"vendor/lib/python2.7/site-packages"

    ["Markdown", "Cheetah"].each do |r|
      resource(r).stage do
        system "python", *Language::Python.setup_install_args(libexec/"vendor")
      end
    end

    begin
      # Fix "ld: file not found: /usr/lib/system/libsystem_darwin.dylib" for lxml
      ENV["SDKROOT"] = MacOS.sdk_path if MacOS.version == :sierra

      resource("lxml").stage do
        system "python", *Language::Python.setup_install_args(libexec/"vendor")
      end
    ensure
      ENV.delete("SDKROOT")
    end

    resource("cppzmq").stage include.to_s

    args = std_cmake_args
    args << "-DGR_PKG_CONF_DIR=#{etc}/gnuradio/conf.d"
    args << "-DGR_PREFSDIR=#{etc}/gnuradio/conf.d"

    args << "-DENABLE_DEFAULT=OFF"
    enabled_components = %w[gr-analog gr-fft volk gr-filter gnuradio-runtime
                            gr-blocks gr-pager gr-noaa gr-channels gr-audio
                            gr-fcd gr-vocoder gr-fec gr-digital gr-dtv gr-atsc
                            gr-trellis gr-zeromq]
    if build.with? "python@2"
      enabled_components << "python"
      enabled_components << "gr-utils"
      enabled_components << "grc"
      enabled_components << "gr-qtgui"
      enabled_components << "gr-wxgui" if build.with? "wxpython"
    end
    enabled_components << "gr-wavelet"
    enabled_components << "gr-video-sdl" if build.with? "sdl"
    enabled_components << "gr-uhd" if build.with? "uhd"
    enabled_components << "doxygen" if build.with? "doxygen"
    enabled_components << "sphinx" if build.with? "sphinx"

    enabled_components.each do |c|
      args << "-DENABLE_#{c.upcase.split("-").join("_")}=ON"
    end

    mkdir "build" do
      system "cmake", "..", *args
      system "make"
      system "make", "install"
    end

    rm bin.children.reject(&:executable?)
    bin.env_script_all_files(libexec/"bin", :PYTHONPATH => ENV["PYTHONPATH"])
  end

  test do
    assert_match version.to_s, shell_output("#{bin}/gnuradio-config-info -v")

    (testpath/"test.c++").write <<~EOS
      #include <gnuradio/top_block.h>
      #include <gnuradio/blocks/null_source.h>
      #include <gnuradio/blocks/null_sink.h>
      #include <gnuradio/blocks/head.h>
      #include <gnuradio/gr_complex.h>

      class top_block : public gr::top_block {
      public:
        top_block();
      private:
        gr::blocks::null_source::sptr null_source;
        gr::blocks::null_sink::sptr null_sink;
        gr::blocks::head::sptr head;
      };

      top_block::top_block() : gr::top_block("Top block") {
        long s = sizeof(gr_complex);
        null_source = gr::blocks::null_source::make(s);
        null_sink = gr::blocks::null_sink::make(s);
        head = gr::blocks::head::make(s, 1024);
        connect(null_source, 0, head, 0);
        connect(head, 0, null_sink, 0);
      }

      int main(int argc, char **argv) {
        top_block top;
        top.run();
      }
    EOS
    system ENV.cxx, "-L#{lib}", "-L#{Formula["boost"].opt_lib}",
           "-lgnuradio-blocks", "-lgnuradio-runtime", "-lgnuradio-pmt",
           "-lboost_system", testpath/"test.c++", "-o", testpath/"test"
    system "./test"

    if build.with? "python@2"
      (testpath/"test.py").write <<~EOS
        from gnuradio import blocks
        from gnuradio import gr

        class top_block(gr.top_block):
            def __init__(self):
                gr.top_block.__init__(self, "Top Block")
                self.samp_rate = 32000
                s = gr.sizeof_gr_complex
                self.blocks_null_source_0 = blocks.null_source(s)
                self.blocks_null_sink_0 = blocks.null_sink(s)
                self.blocks_head_0 = blocks.head(s, 1024)
                self.connect((self.blocks_head_0, 0),
                             (self.blocks_null_sink_0, 0))
                self.connect((self.blocks_null_source_0, 0),
                             (self.blocks_head_0, 0))

        def main(top_block_cls=top_block, options=None):
            tb = top_block_cls()
            tb.start()
            tb.wait()

        main()
      EOS
      system "python2.7", testpath/"test.py"

      cd testpath do
        system "#{bin}/gr_modtool", "newmod", "test"

        cd "gr-test" do
          system "#{bin}/gr_modtool", "add", "-t", "general", "test_ff", "-l",
                 "python", "-y", "--argument-list=''", "--add-python-qa"
        end
      end
    end
  end
end
cartr commented 6 years ago

I'd be happy to include this formula in my tap. Could you please submit a pull request with it?