# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=libquotient
pkgver=0.8.2
pkgrel=0
pkgdesc="Qt library for cross-platform clients for Matrix"
url="https://github.com/quotient-im/libQuotient"
arch="all !armhf" # blocked by qt5-qtmultimedia
license="LGPL-2.1-or-later"
depends_dev="
	olm-dev
	qt5-qtbase-dev
	qt5-qtmultimedia-dev
	qt6-qtbase-dev
	qtkeychain-dev
	"
makedepends="$depends_dev
	cmake
	samurai
	"
subpackages="$pkgname-qt5 $pkgname-qt6 $pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/quotient-im/libQuotient/archive/refs/tags/$pkgver.tar.gz"
builddir="$srcdir/libQuotient-$pkgver"

build() {
	CXXFLAGS="$CXXFLAGS -flto=auto" \

	msg "Building for Qt5"
	cmake -B build-qt5 -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DBUILD_TESTING=True \
		-DQuotient_ENABLE_E2EE=True \
		-DQuotient_INSTALL_TESTS=False
	cmake --build build-qt5

	msg "Building for Qt6"
	cmake -B build-qt6 -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DBUILD_TESTING=True \
		-DBUILD_WITH_QT6=ON \
		-DQuotient_ENABLE_E2EE=True \
		-DQuotient_INSTALL_TESTS=False
	cmake --build build-qt6
}

check() {
	# testolmaccount requires a running Matrix homeserver
	ctest --test-dir build-qt5 --output-on-failure -E "testolmaccount"
	ctest --test-dir build-qt6 --output-on-failure -E "testolmaccount"
}

package() {
	DESTDIR="$pkgdir" cmake --install build-qt5
	DESTDIR="$pkgdir" cmake --install build-qt6
	# android only
	rm -r "$pkgdir"/usr/share/ndk-modules
}

qt5() {
	pkgdesc="$pkgdesc (qt5)"
	amove usr/lib/libQuotient.so.*
}

qt6() {
	pkgdesc="$pkgdesc (qt6)"
	amove usr/lib/libQuotientQt6.so.*
}

sha512sums="
3d971439f8a89609930ca1648f6cf1bdb59f3ad492af1a15a7f8a13d06c81bd5bfffa1dd732ef5156fab8a9ea2ba3e98376bf76511db17bdeee17641a772b762  libquotient-0.8.2.tar.gz
"
