# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=kdb
pkgver=3.2.0
pkgrel=11
pkgdesc="Database connectivity and creation framework for various database vendors"
url="https://community.kde.org/KDb"
# armhf blocked by extra-cmake-modules
arch="all !armhf"
license="LGPL-2.0-or-later"
makedepends="
	extra-cmake-modules
	icu-dev
	kcoreaddons5-dev
	mariadb-dev
	postgresql-dev
	python3
	qt5-qtbase-dev
	qt5-qttools-dev
	samurai
	sqlite-dev
	"
subpackages="$pkgname-dev $pkgname-lang $pkgname-sqlite $pkgname-mysql $pkgname-postgresql"
source="https://download.kde.org/stable/kdb/src/kdb-$pkgver.tar.xz
	0001-fix-build-with-newer-qt.patch
	0002-fix-build-with-postgresql-12+.patch
	cmake-postgresql12+.patch
	"

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DPYTHON_EXECUTABLE=/usr/bin/python3
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sqlite() {
	pkgdesc="$pkgdesc (sqlite driver)"

	amove \
		usr/lib/qt5/plugins/kdb3/kdb_sqlitedriver.so \
		usr/lib/qt5/plugins/kdb3/sqlite3/kdb_sqlite_icu.so \
		usr/bin/kdb3_sqlite3_dump
}

mysql() {
	pkgdesc="$pkgdesc (mysql driver)"

	amove usr/lib/qt5/plugins/kdb3/kdb_mysqldriver.so
}

postgresql() {
	pkgdesc="$pkgdesc (postgresql driver)"

	amove usr/lib/qt5/plugins/kdb3/kdb_postgresqldriver.so
}

sha512sums="
7df22f2c5b6e20ae3de71cb6c76b234d2f1f33b2abcdffa85be313c63d067a40a85ed102b6256207315db08ced5d69f8bc40afdf84a188463713a6b2ffdb2df7  kdb-3.2.0.tar.xz
7fc18bd99d45ed6f874d7aceff271d6262bae550340b243414026c1683837a27b6e261a992a187f4fbebfdf5ac5fd67400528b6d1b3b9c33abb35fe4237989bf  0001-fix-build-with-newer-qt.patch
c7d6fe068bf1dfd206d96e1214595d7001ce03cc591837bbb1e500d440178d95eedb3f07d2fe4a5d9c07fcfe6dad0ee5e0a74ede5ecca4e09572dea1ca35110b  0002-fix-build-with-postgresql-12+.patch
acb5ba34003511449658c745c61ab70f0c9cc322b0f21cd6a3624b03a3e89bea26efcc7826b4eaa21ea5ccec0bdd932d26b598cf4765506079ae4baca39ebcd2  cmake-postgresql12+.patch
"
