# Template file for 'qt6-declarative'
pkgname=qt6-declarative
version=6.6.0
revision=1
build_style=cmake
configure_args="-DQT_BUILD_TESTS=ON"
hostmakedepends="qt6-base perl pkg-config wayland-devel qt6-shadertools python3"
makedepends="qt6-base-devel Vulkan-Headers qt6-shadertools-devel"
short_desc="Cross-platform application and UI framework - Declarative"
maintainer="John <me@johnnynator.dev>"
license="GPL-3.0-only with Qt-GPL-exception-1.0, LGPL-3.0-only, GPL-2.0-or-later"
homepage="https://www.qt.io"
distfiles="https://download.qt.io/official_releases/qt/${version%.*}/${version}/submodules/qtdeclarative-everywhere-src-${version}.tar.xz"
checksum=1b539bb0a918c8f0307fd07bd4ef0334bf7f8934bbc2eabfc04c433a7d7fa331
replaces="qt6-quickcontrols2>=0"

if [ "$CROSS_BUILD" ]; then
	configure_args+=" -DQT_FORCE_BUILD_TOOLS=true"
	hostmakedepends+=" qt6-declarative-host-tools"
fi


if [ "$XBPS_TARGET_ENDIAN" = "be" ]; then
	broken="shader compilation fails"
fi

do_check() {
	cd build
	export QML2_IMPORT_PATH="$wrksrc/build/lib${XBPS_TARGET_WORDSIZE}/qt6/qml"
	export QT_BUILD_BIN_PATH=${wrksrc}/build/lib${XBPS_TARGET_WORDSIZE}/qt6/bin
	export QT_BUILD_LIBEXEC_PATH=${wrksrc}/build/lib${XBPS_TARGET_WORDSIZE}/qt6/libexec
	local broken="tst_qqmllocale|text|tst_qquickwidget"
	# requires qt6-declarative installed
	broken+="|module_includes|cmake_tooling_imports|empty_qmldir"
	broken+="|qtquickcompiler|qmlquery"
	# Need to investigate
	broken+="|tst_qqmldebugjs|tst_qqmljsscope"
	broken+="|tst_qqmlpreview|tst_qmllint|tst_material"
	broken+="|tst_qml|tst_dom_all|tst_basic|tst_fusion"
	broken+="|tst_imagine|tst_universal|tst_sanity"
	# can't find the source
	broken+="|tst_qmltc_qprocess"
	broken+="|tst_qquickfiledialogimpl"
	broken+="|tst_qquickfolderdialogimpl"
	broken+="|tst_qmlimportscanner|tst_qqmlextensionplugin"
	# unknown
	broken+="|tst_qmldomitem|tst_dom_alli"
	# cmake
	broken+="|test_qml_app_deployment|cmake_test_common_import_path"
	ctest -E "($broken)"
}

post_install() {
	rm -rf ${DESTDIR}/usr/tests
	# Only build in -DQT_BUILD_TESTS=ON, for self-test
	rm -f ${DESTDIR}/usr/lib/qt6/bin/testapp
	rm -f ${DESTDIR}/usr/lib/qt6/bin/qqmldebug*
}

qt6-quick-test_package() {
	depends="${sourcepkg}>=${version}_${revision}"
	short_desc+=" - test"
	pkg_install() {
		vmove "usr/lib/libQt6QuickTest.so.*"
		vmove usr/lib/qt6/qml/QtTest
		vmove usr/lib/qt6/qml/Qt/test
		vmove usr/lib/qt6/bin/qmltestrunner
	}
}

qt6-declarative-tools_package() {
	depends="${sourcepkg}>=${version}_${revision}"
	short_desc+=" - tools"
	pkg_install() {
		vmove usr/lib/qt6/plugins/qmltooling
		vmove usr/lib/qt6/plugins/qmllint
		for bin in qmlcachegen qmlimportscanner qmltyperegistrar; do
			vmove usr/lib/qt6/libexec/$bin
		done
		for bin in qmlformat qmllint qmlpreview qmlprofiler; do
			vmove usr/lib/qt6/bin/$bin
		done
	}
}

qt6-declarative-host-tools_package() {
	# The CMake for Tools requires all binaries to be available
	depends="qt6-quick-test>=${version}_${revision} qt6-base>=${version}
	 qt6-declarative-tools>=${version}_${revision}"
	short_desc+=" - host tools"
	pkg_install() {
		vmove "usr/lib/cmake/*Tools"
	}
}

qt6-declarative-devel_package() {
	depends="${sourcepkg}>=${version}_${revision} qt6-base-devel>=${version}_1
	 qt6-declarative-host-tools>=${version}_${revision}"
	short_desc+=" - development files"
	replaces="qt6-quickcontrols2-devel>=0"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/qt6/metatypes
		vmove usr/lib/pkgconfig
		vmove usr/lib/qt6/mkspecs
		vmove "usr/lib/*.so"
		vmove "usr/lib/*.a"
		vmove "usr/lib/*.prl"
		vmove usr/lib/qt6/modules
		for _f in ${DESTDIR}/usr/lib/cmake/*; do
			case "$_f" in
			*Tools) ;;
			*)	vmove "usr/lib/cmake/${_f##*/}" ;;
			esac
		done
	}
}
