# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=kdstatemachineeditor
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-qt5"
pkgver=1.2.8
pkgrel=1
pkgdesc="Library for visualizing and editing state charts (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://kdab.github.io/KDStateMachineEditor/"
msys2_repository_url="https://github.com/KDAB/KDStateMachineEditor/"
license=('spdx:LGPL-2.1-or-later')
depends=(${MINGW_PACKAGE_PREFIX}-graphviz
         ${MINGW_PACKAGE_PREFIX}-qt5-base
         ${MINGW_PACKAGE_PREFIX}-qt5-quickcontrols2
         ${MINGW_PACKAGE_PREFIX}-qt5-remoteobjects
         ${MINGW_PACKAGE_PREFIX}-qt5-scxml
         ${MINGW_PACKAGE_PREFIX}-qt5-xmlpatterns)
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             ${MINGW_PACKAGE_PREFIX}-cmake
             ${MINGW_PACKAGE_PREFIX}-extra-cmake-modules
             ${MINGW_PACKAGE_PREFIX}-ninja
             ${MINGW_PACKAGE_PREFIX}-doxygen)
source=(https://github.com/KDAB/KDStateMachineEditor/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz
        001-find-graphviz.patch)
noextract=(${_realname}-${pkgver}.tar.gz)
sha256sums=('8676276debd1f8333794aba08d643660f36b698ca4c9711ce0a03c7a84f03e0c'
            '7d6c4e7420c6277352f9b4e01c3b68ebe5b91f292363d59fa8ff2661ce821b8f')
validpgpkeys=(E86C000370B1B9E2A9191AD53DBFB6882C9358FB) # KDAB Products <info@kdab.com>

prepare() {
  [[ -d "${srcdir}"/${_realname}-${pkgver} ]] && rm -rf "${srcdir}"/${_realname}-${pkgver}
  tar -xf "${srcdir}"/${_realname}-${pkgver}.tar.gz -C "${srcdir}" || true

  cd ${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/001-find-graphviz.patch
}

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  LDFLAGS+=" -L$(cygpath -am ${MINGW_PREFIX}/lib/binutils)"
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=;-DECM_MKSPECS_INSTALL_DIR;" \
  ${MINGW_PREFIX}/bin/cmake.exe \
      -G "Ninja" \
      -DCMAKE_BUILD_TYPE=RelWithDebInfo \
      -DCMAKE_INSTALL_OLDINCLUDEDIR=${MINGW_PREFIX}/include \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DECM_MKSPECS_INSTALL_DIR=${MINGW_PREFIX}/share/qt5/mkspecs/modules \
      -DBUILD_QT6=OFF \
      -DBUILD_TESTS=OFF \
      -DGRAPHVIZ_ROOT=${MINGW_PREFIX} \
      ${extra_conf} \
      ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd build-${MSYSTEM}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --build ./ --target install
}
