makedepends=(cmake llvm libxslt python-setuptools qt6-3d qt6-charts qt6-connectivity qt6-datavis3d
             qt6-multimedia qt6-networkauth qt6-positioning qt6-quick3d qt6-remoteobjects qt6-scxml
             qt6-sensors qt6-serialbus qt6-serialport qt6-shadertools qt6-speech qt6-svg qt6-tools
             qt6-webengine qt6-websockets)

description="Generates bindings for C++ libraries using CPython source code"
url="http://qt-project.org/"

packager="Great-OS Team"
maintainer="Great-OS Team"

name=pyside6
version=6.10.2
release=2

_qtver=$version
_pkgfqn=pyside-setup-${_qtver}

source=(https://github.com/pyside/pyside-setup/archive/refs/tags/v${version}.tar.gz
        fix-header-install-dir.patch)

prepare() {
  cd ${_pkgfqn}

  patch -Np1 -i ../fix-header-install-dir.patch
}

build() {
  mkdir -pv build && cd build

  cmake ../${_pkgfqn}\
        -DCMAKE_INSTALL_PREFIX=/usr \
        -DCMAKE_BUILD_TYPE=None \
        -DBUILD_TESTS=OFF \
        -DSHIBOKEN_PYTHON_LIBRARIES="$(pkg-config python3-embed --libs)" \
        -DFORCE_LIMITED_API=no \
        -DNO_QT_TOOLS=yes


  PYTHONPATH="$PWD"/sources cmake --build .
}

package() {
  for folder in shiboken6 pyside6; do
    DESTDIR=$PKG cmake --install build/sources/$folder
  done

  # Fix CMake config files to use correct absolute paths (OpenSUSE solution)
    # The upstream build is designed for wheel installation with relative paths,
    # but for system installation we need absolute paths
    sed -i 's#/typesystems#/share/PySide6/typesystems#g' $PKG/usr/lib/cmake/PySide6/*.cmake
    sed -i 's#/glue#/share/PySide6/glue#g' $PKG/usr/lib/cmake/PySide6/*.cmake
}
