# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=kdsoap
pkgver=2.2.0
pkgrel=0
pkgdesc="Additional components to increase the functionality of KIO"
# armhf blocked by extra-cmake-modules
arch="all !armhf"
url="https://www.kdab.com/development-resources/qt-tools/kd-soap/"
license="LGPL-2.1-only AND LGPL-3.0-only AND (GPL-2.0-only OR GPL-3.0-only) AND AGPL-3.0-only"
depends_dev="qt5-qtbase-dev"
makedepends="
	cmake
	doxygen
	qt5-qtbase-dev
	qt6-qtbase-dev
	samurai
	"
source="https://github.com/KDAB/KDSoap/releases/download/kdsoap-$pkgver/kdsoap-$pkgver.tar.gz"
subpackages="$pkgname-qt6-dev:qt6_dev $pkgname-dev $pkgname-doc $pkgname-qt6 $pkgname-qt5"

build() {
	cmake -B build-qt5 -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DKDSoap_TESTS=true \
		-DKDSoap_EXAMPLES=false \
		-DKDSoap_QT6=false
	cmake -B build-qt6 -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DKDSoap_TESTS=true \
		-DKDSoap_EXAMPLES=false \
		-DKDSoap_QT6=true

	cmake --build build-qt5
	cmake --build build-qt6
}

check() {
	# kdsoap-webcalls, kdsoap-webcalls_wsdl and kdsoap-test_calc require network access
	# kdsoap-test_wsdl_document is broken on s390x, https://github.com/KDAB/KDSoap/issues/245
	local skipped_tests="kdsoap-("
	local tests="
		webcalls
		webcalls_wsdl
		test_calc
		"
	[ "$CARCH" = "s390x" ] && tests="$tests test_wsdl_document"
	for test in $tests; do
		skipped_tests="$skipped_tests|$test"
	done
	skipped_tests="$skipped_tests)"
	ctest --test-dir build-qt5 --output-on-failure -E "$skipped_tests"
	ctest --test-dir build-qt6 --output-on-failure -E "$skipped_tests"
}

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

qt5() {
	amove usr/lib
}

qt6() {
	amove usr/lib/*qt6*
}

dev() {
	default_dev

	amove usr/bin/kdwsdl2cpp
	amove usr/share/mkspecs

	rm -r "$subpkgdir"/usr/lib/*qt6*
}

qt6_dev() {
	depends="!$pkgname-dev qt6-qtbase-dev"

	DESTDIR="$subpkgdir" cmake --install "$builddir"/build-qt6
	rm "$subpkgdir"/usr/lib/libkdsoap-qt6.so.*
	rm "$subpkgdir"/usr/lib/libkdsoap-server-qt6.so.*
	rm -r "$subpkgdir"/usr/share/doc
}

sha512sums="
6ed5cd6a0d02a9faf6881facbd28391c553b3671512153ecd058ab53bfbe9d3f0afa3704d580e66010ddf6a3de7e578a632339f8c1ae7529c28f9d5fd7d1eb5f  kdsoap-2.2.0.tar.gz
"
