# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_realname=tgui
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.10.0
pkgrel=1
pkgdesc="Cross-platform C++ GUI library (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://tgui.eu/'
msys2_repository_url='https://github.com/texus/TGUI'
license=('spdx:Zlib')
depends=("${MINGW_PACKAGE_PREFIX}-sdl3"
         "${MINGW_PACKAGE_PREFIX}-sdl3-ttf")
makedepends=("${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-doxygen")

source=("${msys2_repository_url}/archive/v${pkgver}/${_realname^^}-${pkgver}.tar.gz")
sha256sums=('b25a5f8aca7823314e268118015aa14a8eb65956e09f447010230df10dc560b0')

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  # static build
  mkdir -p "${srcdir}"/build-${MSYSTEM}-static && cd "${srcdir}"/build-${MSYSTEM}-static
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ${extra_config} \
    -DTGUI_SHARED_LIBS=OFF \
    -DTGUI_BACKEND=SDL_RENDERER \
    -DTGUI_USE_SDL3=ON \
    ../${_realname^^}-${pkgver}
  ${MINGW_PREFIX}/bin/cmake --build .

  # shared build
  mkdir -p "${srcdir}"/build-${MSYSTEM}-shared && cd "${srcdir}"/build-${MSYSTEM}-shared
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ${extra_config} \
    -DTGUI_SHARED_LIBS=ON \
    -DTGUI_BUILD_DOC=ON \
    -DTGUI_BACKEND=SDL_RENDERER \
    -DTGUI_USE_SDL3=ON \
    ../${_realname^^}-${pkgver}
  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  # Static Install
  cd "${srcdir}/build-${MSYSTEM}-static"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .

  # Shared Install
  cd "${srcdir}/build-${MSYSTEM}-shared"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .

  install -Dm644 "${srcdir}/${_realname^^}-${pkgver}/license.txt" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/license.txt"
}
