pkgname=yyjson
pkgver=0.12.0
pkgdesc="A high performance JSON library written in ANSI C"
arch=('x86_64')
homepage="https://ibireme.github.io/yyjson"
license=('MIT')
sources=("${pkgname}-${pkgver}.tar.gz")
urls=("https://github.com/ibireme/yyjson/archive/refs/tags/${pkgver}.tar.gz")
md5sums=("a0a4fe2ae717277125fdebc60630ddf1")

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
}

src_build() {
  cmake -B build \
    -DCMAKE_BUILD_TYPE='None' \
    -DCMAKE_INSTALL_PREFIX='/usr' \
    -DBUILD_SHARED_LIBS='ON' \
    -DYYJSON_BUILD_TESTS='ON' \
    -Wno-dev
  cmake --build build
}

src_check() {
  ctest --test-dir build --output-on-failure
}

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

  install -Dm 644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
  install -Dm 644 README.md "${pkgdir}/usr/share/doc/${pkgname}/README.md"
  install -Dm 644 doc/*.md -t "${pkgdir}/usr/share/doc/${pkgname}/"
}
