# gwenview - Image viewer
# Generated from manifest.tsv by gen-ports.py. Edit the manifest, not this file,
# unless the package needs something the template cannot express - in which case
# drop a `recipe.local` beside it and it will be preserved.
name=gwenview
version=25.12.0
release=1
desc="Image viewer"
url="https://apps.kde.org/gwenview/"
license="GPL-2.0-or-later"
depend="kf6 qt6-base exiv2"
makedepend="cmake ninja"
source="https://download.kde.org/stable/release-service/25.12.0/src/gwenview-25.12.0.tar.xz"
sha256="SKIP"

build() {
	# CMAKE_PREFIX_PATH pinned to /usr, and find_package() barred from
	# every source of an unwanted host-installed hit:
	#
	# - CMAKE_FIND_USE_PACKAGE_REGISTRY / _SYSTEM_PACKAGE_REGISTRY=OFF:
	#   without this cmake's own registry can find a host-installed copy
	#   of the same library ahead of the one actually being built against
	#   (real, hit by qt6-svg finding the host's Qt6 instead of ScrapLinux's).
	# - CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH=OFF: cmake derives extra
	#   find_package() search prefixes from every PATH entry (stripping a
	#   trailing /bin or /sbin), and this build's PATH includes
	#   /host/usr/bin and /host/bin as a fallback for host tools not yet
	#   packaged for ScrapLinux - without this, that becomes a search prefix
	#   of /host/usr, and find_package quietly resolves a real dependency
	#   to a host copy that was never built against ScrapLinux at all (hit by
	#   pcmanfm-qt finding a host-installed fm-qt6 this way).
	#
	# Deliberately NOT set: CMAKE_FIND_USE_CMAKE_SYSTEM_PATH=OFF and
	# CMAKE_FIND_ROOT_PATH=/usr, both tried and reverted. The former also
	# gates whether find_library()/find_path() (not just find_package())
	# consult CMAKE_PREFIX_PATH at all - turning it off broke plain
	# find_library(OpenGL) against /usr entirely, taking every downstream
	# Qt6Gui consumer down with it. The latter only takes effect while
	# cross-compiling (CMAKE_CROSSCOMPILING true), which this never is -
	# a no-op on its own, but compounded the find_library breakage above
	# when combined with it. CMAKE_PREFIX_PATH=/usr is what actually does
	# the pinning; neither of these was pulling its weight.
	#
	# CMAKE_CXX_FLAGS below adds every Qt module's versioned private-header
	# dir directly: third-party consumers of Qt private headers (LXQt and
	# friends) set -DQt6Foo_PRIVATE_INCLUDE_DIRS by reading
	# Qt6::FooPrivate's INTERFACE_INCLUDE_DIRECTORIES via
	# get_target_property() at configure time - but that property is a
	# generator expression gated on a TARGET_PROPERTY check, and
	# get_target_property() captures it unevaluated, so the variable ends
	# up empty and every private header 404s. Harmless for anything that
	# isn't consuming Qt private headers at all.
	cmake -S "gwenview-25.12.0" -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_BUILD_TYPE=Release \
		-DBUILD_SHARED_LIBS=ON \
		-DCMAKE_PREFIX_PATH=/usr \
		-DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF \
		-DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF \
		-DCMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH=OFF \
		-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
		-DCMAKE_CXX_FLAGS="-I/usr/include/QtCore/6.10.1 -I/usr/include/QtCore/6.10.1/QtCore -I/usr/include/QtGui/6.10.1 -I/usr/include/QtGui/6.10.1/QtGui -I/usr/include/QtWidgets/6.10.1 -I/usr/include/QtWidgets/6.10.1/QtWidgets -I/usr/include/QtDBus/6.10.1 -I/usr/include/QtDBus/6.10.1/QtDBus -I/usr/include/QtNetwork/6.10.1 -I/usr/include/QtNetwork/6.10.1/QtNetwork"
	# cmake itself (a host binary in this chroot) needs LD_LIBRARY_PATH to
	# find its own dependencies, but that same setting poisons anything
	# the build produces and then runs on itself (Qt's own qmlcachegen,
	# built here, loading the host's Qt 6.11 instead of the one just
	# built here alongside it - "undefined symbol ... version
	# Qt_6_PRIVATE_API", a real symbol at a real address in the correct
	# library, just not the one that got loaded).
	unset LD_LIBRARY_PATH
	ninja -C build -j"$JOBS"
}

package() {
	DESTDIR="$pkgdir" ninja -C build install
}
