homebrew-core/Formula/qt-postgresql.rb

88 lines
2.6 KiB
Ruby

class QtPostgresql < Formula
desc "Qt SQL Database Driver"
homepage "https://www.qt.io/"
url "https://download.qt.io/official_releases/qt/6.1/6.1.0/submodules/qtbase-everywhere-src-6.1.0.tar.xz"
sha256 "f7af3c87e96051d09b5abce6c88277c33031bef241ebfe1db4106d33ed0814c4"
license all_of: ["GFDL-1.3-only", "GPL-2.0-only", "GPL-3.0-only", "LGPL-2.1-only", "LGPL-3.0-only"]
bottle do
sha256 cellar: :any, arm64_big_sur: "ce09ac797fb05b6216217c81fe740433f264a77ae950e5d24c6e1ee801f5db4c"
sha256 cellar: :any, big_sur: "9db62a83caf0bf3355557e92de90eb105dd5270652d31b42bca7ee91fcb7e705"
sha256 cellar: :any, catalina: "c87f17807ac40a2db5c7bd43286c93eaef0288a00f91c09a5fa6f62a60da0212"
sha256 cellar: :any, mojave: "b33cd87bdb302989abe299fee46d353c1eec34388b69af39db70bd9844e06d3c"
end
depends_on "cmake" => [:build, :test]
depends_on "postgresql"
depends_on "qt"
def install
args = std_cmake_args + %W[
-DCMAKE_STAGING_PREFIX=#{prefix}
-DFEATURE_sql_ibase=OFF
-DFEATURE_sql_mysql=OFF
-DFEATURE_sql_oci=OFF
-DFEATURE_sql_odbc=OFF
-DFEATURE_sql_psql=ON
-DFEATURE_sql_sqlite=OFF
]
cd "src/plugins/sqldrivers" do
system "cmake", ".", *args
system "cmake", "--build", "."
system "cmake", "--install", "."
end
end
test do
(testpath/"CMakeLists.txt").write <<~EOS
cmake_minimum_required(VERSION #{Formula["cmake"].version})
project(test VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
find_package(Qt6 COMPONENTS Core Sql REQUIRED)
add_executable(test
main.cpp
)
target_link_libraries(test PRIVATE Qt6::Core Qt6::Sql)
EOS
(testpath/"test.pro").write <<~EOS
QT += core sql
QT -= gui
TARGET = test
CONFIG += console debug
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
EOS
(testpath/"main.cpp").write <<~EOS
#include <QCoreApplication>
#include <QtSql>
#include <cassert>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
assert(db.isValid());
return 0;
}
EOS
system "cmake", "-S", ".", "-B", "build", "-DCMAKE_BUILD_TYPE=Debug"
system "cmake", "--build", "build"
system "./build/test"
ENV.delete "CPATH"
system "qmake"
system "make"
system "./test"
end
end