From 67e7aa02813056543f2d31dcd643e7418eb329cb Mon Sep 17 00:00:00 2001 From: PaperChalice Date: Thu, 11 Feb 2021 06:03:16 +0800 Subject: [PATCH] qt@5: add qt@5, versioned formula --- Aliases/qt5 | 2 +- Aliases/qt@5 | 1 - Formula/qt@5.rb | 142 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+), 2 deletions(-) delete mode 120000 Aliases/qt@5 create mode 100644 Formula/qt@5.rb diff --git a/Aliases/qt5 b/Aliases/qt5 index f6482cf9840..ee4b36fe5a4 120000 --- a/Aliases/qt5 +++ b/Aliases/qt5 @@ -1 +1 @@ -../Formula/qt.rb \ No newline at end of file +../Formula/qt@5.rb \ No newline at end of file diff --git a/Aliases/qt@5 b/Aliases/qt@5 deleted file mode 120000 index f6482cf9840..00000000000 --- a/Aliases/qt@5 +++ /dev/null @@ -1 +0,0 @@ -../Formula/qt.rb \ No newline at end of file diff --git a/Formula/qt@5.rb b/Formula/qt@5.rb new file mode 100644 index 00000000000..474db18540b --- /dev/null +++ b/Formula/qt@5.rb @@ -0,0 +1,142 @@ +# Patches for Qt must be at the very least submitted to Qt's Gerrit codereview +# rather than their bug-report Jira. The latter is rarely reviewed by Qt. +class QtAT5 < Formula + desc "Cross-platform application and UI framework" + homepage "https://www.qt.io/" + url "https://download.qt.io/official_releases/qt/5.15/5.15.2/single/qt-everywhere-src-5.15.2.tar.xz" + mirror "https://mirrors.dotsrc.org/qtproject/archive/qt/5.15/5.15.2/single/qt-everywhere-src-5.15.2.tar.xz" + mirror "https://mirrors.ocf.berkeley.edu/qt/archive/qt/5.15/5.15.2/single/qt-everywhere-src-5.15.2.tar.xz" + sha256 "3a530d1b243b5dec00bc54937455471aaa3e56849d2593edb8ded07228202240" + license all_of: ["GFDL-1.3-only", "GPL-2.0-only", "GPL-3.0-only", "LGPL-2.1-only", "LGPL-3.0-only"] + + keg_only :versioned_formula + + depends_on "pkg-config" => :build + depends_on xcode: :build + depends_on macos: :sierra + + uses_from_macos "gperf" => :build + uses_from_macos "bison" + uses_from_macos "flex" + uses_from_macos "sqlite" + + # Find SDK for 11.x macOS + # Upstreamed, remove when Qt updates Chromium + patch do + url "https://raw.githubusercontent.com/Homebrew/formula-patches/92d4cf/qt/5.15.2.diff" + sha256 "fa99c7ffb8a510d140c02694a11e6c321930f43797dbf2fe8f2476680db4c2b2" + end + + # Patch for qmake on ARM + # https://codereview.qt-project.org/c/qt/qtbase/+/327649 + if Hardware::CPU.arm? + patch do + url "https://raw.githubusercontent.com/Homebrew/formula-patches/9dc732/qt/qt-split-arch.patch" + sha256 "36915fde68093af9a147d76f88a4e205b789eec38c0c6f422c21ae1e576d45c0" + directory "qtbase" + end + end + + def install + args = %W[ + -verbose + -prefix #{prefix} + -release + -opensource -confirm-license + -system-zlib + -qt-libpng + -qt-libjpeg + -qt-freetype + -qt-pcre + -nomake examples + -nomake tests + -no-rpath + -pkg-config + -dbus-runtime + ] + + if Hardware::CPU.arm? + # Temporarily fixes for Apple Silicon + args << "-skip" << "qtwebengine" << "-no-assimp" + else + # Should be reenabled unconditionnaly once it is fixed on Apple Silicon + args << "-proprietary-codecs" + end + + system "./configure", *args + + # Remove reference to shims directory + inreplace "qtbase/mkspecs/qmodule.pri", + /^PKG_CONFIG_EXECUTABLE = .*$/, + "PKG_CONFIG_EXECUTABLE = #{Formula["pkg-config"].opt_bin/"pkg-config"}" + system "make" + ENV.deparallelize + system "make", "install" + + # Some config scripts will only find Qt in a "Frameworks" folder + frameworks.install_symlink Dir["#{lib}/*.framework"] + + # The pkg-config files installed suggest that headers can be found in the + # `include` directory. Make this so by creating symlinks from `include` to + # the Frameworks' Headers folders. + Pathname.glob("#{lib}/*.framework/Headers") do |path| + include.install_symlink path => path.parent.basename(".framework") + end + + # Move `*.app` bundles into `libexec` to expose them to `brew linkapps` and + # because we don't like having them in `bin`. + # (Note: This move breaks invocation of Assistant via the Help menu + # of both Designer and Linguist as that relies on Assistant being in `bin`.) + libexec.mkpath + Pathname.glob("#{bin}/*.app") { |app| mv app, libexec } + end + + def caveats + s = <<~EOS + We agreed to the Qt open source license for you. + If this is unacceptable you should uninstall. + EOS + + if Hardware::CPU.arm? + s += <<~EOS + + This version of Qt on Apple Silicon does not include QtWebEngine + EOS + end + + s + end + + test do + (testpath/"hello.pro").write <<~EOS + QT += core + QT -= gui + TARGET = hello + CONFIG += console + CONFIG -= app_bundle + TEMPLATE = app + SOURCES += main.cpp + EOS + + (testpath/"main.cpp").write <<~EOS + #include + #include + + int main(int argc, char *argv[]) + { + QCoreApplication a(argc, argv); + qDebug() << "Hello World!"; + return 0; + } + EOS + + # Work around "error: no member named 'signbit' in the global namespace" + ENV.delete "CPATH" + + system bin/"qmake", testpath/"hello.pro" + system "make" + assert_predicate testpath/"hello", :exist? + assert_predicate testpath/"main.o", :exist? + system "./hello" + end +end