Skip to content

Add Qt formula #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 195 additions & 0 deletions Formula/sqlb-qt@5.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
# 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 SqlbQtAT5 < 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.16/single/qt-everywhere-opensource-src-5.15.16.tar.xz"
# version "5.15.16"
# NOTE: Use *.diff for GitLab/KDE patches to avoid their checksums changing.
sha256 "efa99827027782974356aceff8a52bd3d2a8a93a54dd0db4cca41b5e35f1041c"
license all_of: ["GFDL-1.3-only", "GPL-2.0-only", "GPL-3.0-only", "LGPL-2.1-only", "LGPL-3.0-only"]
revision 1

livecheck do
url "https://download.qt.io/official_releases/qt/5.15/"
regex(%r{href=["']?v?(\d+(?:\.\d+)+)/?["' >]}i)
end

bottle do
root_url "https://github.com/lucydodo/homebrew-tap/releases/download/sqlb-qt@5-5.15.16_1"
sha256 cellar: :any, arm64_sonoma: "be4927a0d13ae0decd8b1ad449adf3d0290e57b14505d0fcc3e7d4f2895ea2fc"
end

keg_only :versioned_formula

depends_on arch: :arm64

# Fix build with Xcode 14.3.
# https://bugreports.qt.io/browse/QTBUG-112906
patch do
url "https://invent.kde.org/qt/qt/qtlocation-mapboxgl/-/commit/5a07e1967dcc925d9def47accadae991436b9686.diff"
sha256 "4f433bb009087d3fe51e3eec3eee6e33a51fde5c37712935b9ab96a7d7571e7d"
directory "qtlocation/src/3rdparty/mapbox-gl-native"
end

# CVE-2023-51714
# Remove with Qt 5.15.17
patch do
url "https://download.qt.io/official_releases/qt/5.15/0001-CVE-2023-51714-qtbase-5.15.diff"
sha256 "2129058a5e24d98ee80a776c49a58c2671e06c338dffa7fc0154e82eef96c9d4"
directory "qtbase"
end
patch do
url "https://download.qt.io/official_releases/qt/5.15/0002-CVE-2023-51714-qtbase-5.15.diff"
sha256 "99d5d32527e767d6ab081ee090d92e0b11f27702619a4af8966b711db4f23e42"
directory "qtbase"
end

# CVE-2024-25580
# Remove with Qt 5.15.17
patch do
url "https://download.qt.io/official_releases/qt/5.15/CVE-2024-25580-qtbase-5.15.diff"
sha256 "7cc9bf74f696de8ec5386bb80ce7a2fed5aa3870ac0e2c7db4628621c5c1a731"
directory "qtbase"
end

# CVE-2024-36048
# Remove with Qt 5.15.17
patch do
url "https://download.qt.io/official_releases/qt/5.15/CVE-2024-36048-qtnetworkauth-5.15.diff"
sha256 "e5d385d636b5241b59ac16c4a75359e21e510506b26839a4e2033891245f33f9"
directory "qtnetworkauth"
end

# CVE-2024-39936
# Remove with Qt 5.15.18
patch do
url "https://download.qt.io/official_releases/qt/5.15/CVE-2024-39936-qtbase-5.15.patch"
sha256 "2cc23afba9d7e48f8faf8664b4c0324a9ac31a4191da3f18bd0accac5c7704de"
directory "qtbase"
end

def install
# Determine the minimum macOS version.
# Match the required version of the DB Browser for SQLite app.
ENV["MACOSX_DEPLOYMENT_TARGET"] = "10.13"
ENV.append "CPPFLAGS", "-mmacosx-version-min=10.13"
ENV.append "LDFLAGS", "-mmacosx-version-min=10.13"

args = [
"-device-option",
"QMAKE_APPLE_DEVICE_ARCHS=x86_64 arm64",
"-verbose",
"-prefix",
prefix.to_s,
"-release",
"-opensource",
"-confirm-license",
"-nomake",
"examples",
"-nomake",
"tests",
]

args << "-no-rpath"
args << "-no-assimp" if Hardware::CPU.arm?

# Work around Clang failure in bundled Boost and V8:
# error: integer value -1 is outside the valid range of values [0, 3] for this enumeration type
if DevelopmentTools.clang_build_version >= 1500
args << "QMAKE_CXXFLAGS+=-Wno-enum-constexpr-conversion"
inreplace "qtwebengine/src/3rdparty/chromium/build/config/compiler/BUILD.gn",
/^\s*"-Wno-thread-safety-attributes",$/,
"\\0 \"-Wno-enum-constexpr-conversion\","
end

system "./configure", *args
system "make"
system "make", "install"

# Install a qtversion.xml to ease integration with QtCreator
# As far as we can tell, there is no ability to make the Qt buildsystem
# generate this and it's in the Qt source tarball at all.
# Multiple people on StackOverflow have asked for this and it's a pain
# to add Qt to QtCreator (the official IDE) without it.
# Given Qt upstream seems extremely unlikely to accept this: let's ship our
# own version.
# If you read this and you can eliminate it or upstream it: please do!
# More context in https://github.com/Homebrew/homebrew-core/pull/124923
qtversion_xml = share/"qtcreator/QtProject/qtcreator/qtversion.xml"
qtversion_xml.dirname.mkpath
qtversion_xml.write <<~XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorQtVersions>
<qtcreator>
<data>
<variable>QtVersion.0</variable>
<valuemap type="QVariantMap">
<value type="int" key="Id">1</value>
<value type="QString" key="Name">Qt %{Qt:Version} (#{opt_prefix})</value>
<value type="QString" key="QMakePath">#{opt_bin}/qmake</value>
<value type="QString" key="QtVersion.Type">Qt4ProjectManager.QtVersion.Desktop</value>
<value type="QString" key="autodetectionSource"></value>
<value type="bool" key="isAutodetected">false</value>
</valuemap>
</data>
<data>
<variable>Version</variable>
<value type="int">1</value>
</data>
</qtcreator>
XML

# Move `*.app` bundles into `libexec` to expose them to `brew linkapps` and
# because we don't like having them in `bin`.
bin.glob("*.app") do |app|
libexec.install app
bin.write_exec_script libexec/app.basename/"Contents/MacOS"/app.stem
end
end

def caveats
<<~EOS
We agreed to the Qt open source license for you.
If this is unacceptable you should uninstall.

You can add Homebrew's Qt to QtCreator's "Qt Versions" in:
Preferences > Qt Versions > Link with Qt...
pressing "Choose..." and selecting as the Qt installation path:
#{opt_prefix}
EOS
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 <QCoreApplication>
#include <QDebug>

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_path_exists testpath/"hello"
assert_path_exists testpath/"main.o"
system "./hello"
end
end