# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=podofo
pkgver=0.10.3
pkgrel=0
# tests
_resources=4afe5c3fdb543a4347681b2e52252f1b10f12f24
pkgdesc="C++ library to work with the PDF file format"
url="https://podofo.sourceforge.net/"
# s390x: fails bunch of tests on big endian
arch="all !s390x"
license="GPL-2.0-only"
makedepends="
	cmake
	fontconfig-dev
	libidn-dev
	libpng-dev
	libxml2-dev
	lua-dev
	openssl-dev
	samurai
	tiff-dev
	"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/podofo/podofo/archive/refs/tags/$pkgver.tar.gz
	podofo-resources-$_resources.tar.gz::https://github.com/podofo/podofo-resources/archive/$_resources.tar.gz
	"

# secfixes:
#   0.9.7-r0:
#     - CVE-2019-9199
#     - CVE-2019-9687
#     - CVE-2018-19532
#     - CVE-2018-20751
#     - CVE-2018-20797
#     - CVE-2019-10723
#     - CVE-2019-20093
#   0.9.6-r0:
#     - CVE-2017-6848
#     - CVE-2017-7378
#     - CVE-2017-7379
#     - CVE-2017-7380
#     - CVE-2017-7381
#     - CVE-2017-7382
#     - CVE-2017-7383
#     - CVE-2017-7994
#     - CVE-2017-8053
#     - CVE-2017-8054
#     - CVE-2017-8378
#     - CVE-2017-8787
#     - CVE-2018-5295
#     - CVE-2018-5296
#     - CVE-2018-5308
#     - CVE-2018-5309
#     - CVE-2018-5783
#     - CVE-2018-6352
#     - CVE-2018-8000
#     - CVE-2018-8001
#     - CVE-2018-8002
#     - CVE-2018-11254
#     - CVE-2018-11255
#     - CVE-2018-11256
#     - CVE-2018-12982
#     - CVE-2018-12983
#   0.9.5-r0:
#     - CVE-2017-6843
#     - CVE-2017-6844
#     - CVE-2017-6845
#     - CVE-2017-6846
#     - CVE-2017-6847
#     - CVE-2017-6849

prepare() {
	default_prepare

	rmdir extern/resources
	ln -sfv "$srcdir"/podofo-resources-$_resources extern/resources
}

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DPODOFO_BUILD_STATIC=0 \
		-DPODOFO_BUILD_TEST="$(want_check && echo ON || echo OFF)" \
		-DPODOFO_HAVE_JPEG_LIB=ON \
		-DPODOFO_HAVE_PNG_LIB=ON \
		-DPODOFO_HAVE_TIFF_LIB=ON
	cmake --build build
}

check() {
	# testCMYKConstructor fails on ppc64le
	# testHexNames fails on x86 due to non-sse math
	timeout 600 \
	ctest --test-dir build --output-on-failure \
		-E '(testCMYKConstructor|testHexNames)'
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	mkdir -p "$pkgdir"/usr/lib/cmake/
	mv "$pkgdir"/usr/share/podofo "$pkgdir"/usr/lib/cmake/
}

sha512sums="
80fa86ff7f256a69b963451ef741e49c56447084b26481e52d1a079940102b5d51d9ff1c43952bba22bae61d95c8c44eacc08f55cd18999aec6c563f615b2cf5  podofo-0.10.3.tar.gz
4cb33e5a6050ef745cda42b7fdf53fee9f45d4d488555b79c9cdd6680c5265065aac92ad3d72ea0b75eee9a73098f920a3dd61b7728db6d2171888cbc83c6d55  podofo-resources-4afe5c3fdb543a4347681b2e52252f1b10f12f24.tar.gz
"
