# Maintainer: Peter Budai <peterbudai at hotmail.com>

_realname=opencl-icd
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2025.07.22
pkgrel=1
pkgdesc="OpenCL ICD Loader (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/KhronosGroup/OpenCL-ICD-Loader'
msys2_references=(
  'aur: mingw-w64-opencl-icd'
)
license=('spdx:Apache-2.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-opencl-headers"
             "${MINGW_PACKAGE_PREFIX}-tools")
source=("https://github.com/KhronosGroup/OpenCL-ICD-Loader/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('dff7a0b11ad5b63a669358e3476e3dc889a4a361674e5b69b267b944d0794142')

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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -G'Ninja' \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      "${extra_config[@]}" \
      -DBUILD_SHARED_LIBS=ON \
      -DOPENCL_ICD_LOADER_DISABLE_OPENCLON12=ON \
      -DOPENCL_ICD_LOADER_HEADERS_DIR=${MINGW_PREFIX}/include \
      -DBUILD_TESTING=OFF \
      -S OpenCL-ICD-Loader-${pkgver} \
      -B build-${MSYSTEM}

  ${MINGW_PREFIX}/bin/cmake --build build-${MSYSTEM}
}

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

  install -Dm644 "${srcdir}"/OpenCL-ICD-Loader-${pkgver}/LICENSE \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
