# Template file for 'qt6-declarative'
#
# On update, rebuild pkgs with qt6-declarative-private-devel
pkgname=qt6-declarative
version=6.8.2
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-private-devel Vulkan-Headers qt6-shadertools-devel
 qt6-languageserver-private-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=144d876adc8bb55909735143e678d1e24eadcd0a380a0186792d88b731346d56
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

subpackages="qt6-quick-test qt6-declarative-host-tools qt6-declarative-tools
 qt6-declarative-private-devel qt6-declarative-devel"

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 qmlls; 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-private-devel_package() {
	depends="qt6-declarative-devel>=${version}_${revision}"
	short_desc+=" - private development files"
	pkg_install() {
		for dir in $(cd ${DESTDIR} && find usr/include -type d -name private); do
			vmove "$dir"
		done
		vmove "usr/lib/cmake/*Private"
		vmove "usr/lib/qt6/metatypes/*private_*_metatypes.json"
		vmove "usr/lib/qt6/mkspecs/modules/*_private.pri"
		vmove "usr/lib/qt6/modules/*Private.json"
	}
}

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
		vmove usr/lib/cmake
	}
}
