# Maintainer: Martchus <martchus@gmx.net>

# All my PKGBUILDs are managed at https://github.com/Martchus/PKGBUILDs where
# you also find the URL of a binary repository.

_reponame=qtutilities
_cfg=qt6-git
pkgname=qtutilities-$_cfg
_name=${pkgname%-$_cfg}
pkgver=501.0e9637f
pkgrel=1
arch=('i686' 'x86_64' 'armv6h' 'armv7h' 'aarch64')
pkgdesc='Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models (using Qt 6)'
license=('GPL')
depends=('libc++utilities-git.so' 'qt6-base' 'libx11')
makedepends=('cmake' 'git' 'ninja' 'qt6-tools' 'qt6-declarative' 'clang')
optdepends=("$_name-doc: API documentation")
provides=(libqtutilities-qt6-git.so)
url="https://github.com/Martchus/${_reponame}"
source=("${_reponame}::${MARTCHUS_GIT_URL_PREFIX:-git+https://github.com/Martchus}/${_reponame}.git")
sha256sums=('SKIP')

pkgver() {
  cd "$srcdir/${PROJECT_DIR_NAME:-$_reponame}"
  echo "$(git rev-list --count HEAD).$(git rev-parse --short HEAD)"
}

build() {
  cmake \
    -G Ninja \
    -S "${PROJECT_DIR_NAME:-$_reponame}" \
    -B build \
    -DCMAKE_BUILD_TYPE:STRING='Release' \
    -DCMAKE_INSTALL_PREFIX:PATH='/usr' \
    -DCONFIGURATION_NAME:STRING="$_cfg" \
    -DCONFIGURATION_DISPLAY_NAME="Qt 6" \
    -DCONFIGURATION_PACKAGE_SUFFIX:STRING='-git' \
    -DCONFIGURATION_TARGET_SUFFIX:STRING="$_cfg" \
    -DQT_PACKAGE_PREFIX:STRING='Qt6' \
    -DBUILTIN_TRANSLATIONS:BOOL=ON \
    -DBUILD_SHARED_LIBS:BOOL=ON \
    .
  cmake --build build
}

check() {
  QT_QPA_PLATFORM=offscreen cmake --build build --target check
}

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