# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: team/kde <bribbers@disroot.org>

# The group tag is just to easily find this APKBUILD by some scripts for automation
# group=kde-applications
pkgname=akonadi
pkgver=24.08.1
pkgrel=0
pkgdesc="A cross-desktop storage service for PIM data and meta data providing concurrent read, write, and query access"
# ppc64le, s390x, riscv64, armhf and loongarch64 blocked by kaccounts-integration
arch="all !armhf !ppc64le !s390x !riscv64 !loongarch64"
url="https://community.kde.org/KDE_PIM"
license="LGPL-2.0-or-later"
depends="
	mariadb
	qt6-qtbase-mysql
	qt6-qtbase-sqlite
	"
depends_dev="
	boost-dev
	kcompletion-dev
	kconfig-dev
	kconfigwidgets-dev
	kcoreaddons-dev
	kcrash-dev
	kdbusaddons-dev
	ki18n-dev
	kiconthemes-dev
	kio-dev
	kitemmodels-dev
	kitemviews-dev
	kwidgetsaddons-dev
	kwindowsystem-dev
	kxmlgui-dev
	libxml2-dev
	qt6-qtbase-dev
	shared-mime-info
	sqlite-dev
	"
makedepends="$depends_dev
	extra-cmake-modules
	qt6-qttools-dev
	samurai
	"
checkdepends="
	cmd:dbus-run-session
	xvfb-run
	"
subpackages="$pkgname-dbg $pkgname-dev $pkgname-lang"
_repo_url="https://invent.kde.org/pim/akonadi.git"
source="https://download.kde.org/stable/release-service/$pkgver/src/akonadi-$pkgver.tar.xz"

build() {
	# make -dbg smaller
	export CFLAGS="$CFLAGS -g1"
	export CXXFLAGS="$CXXFLAGS -g1"

	case "$CARCH" in
		armv7) tests=-DBUILD_TESTING=OFF ;;
		*) tests=-DBUILD_TESTING=ON ;;
	esac
	# akonadi recurses while walking e-mail threads, so give it a decent stack
	LDFLAGS="$LDFLAGS -Wl,-z,stack-size=1024768" \
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_DESIGNERPLUGIN=ON \
		$tests
	cmake --build build
}

check() {
	# akonadixml-xmldocumenttest, mimetypecheckertest and akonadi-mysql-testenvironmenttest are broken
	# All sqlite tests are hanging
	# All mysql tests are broken "Cannot connect to non-local host <hostname>"
	# tagmodeltest fails on 32-bit architectures
	local skipped_tests="("
	local tests="
		akonadixml-xmldocument
		mimetypechecker
		akonadi-mysql-testenvironment
		.*sqlite.*
		.*mysql.*
		tagmodel
		"
	case "$CARCH" in
		s390x) tests="$tests
			AkonadiServer-itemcreatehandler
			AkonadiServer-relationhandler
			" ;;
	esac
	for test in $tests; do
		skipped_tests="$skipped_tests|$test"
	done
	skipped_tests="$skipped_tests)test"
	dbus-run-session xvfb-run ctest --test-dir build --output-on-failure -E "$skipped_tests"
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}
sha512sums="
d591d9b073dc468649803fb72c2c90c5fb5ab9c277481c2813ea5c70a814cda3d7e23edc9e28c8525cdfc2f87ec076343ee280766b496d734649f0ba29885d0c  akonadi-24.08.1.tar.xz
"
