# Copyright 1999-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit cmake-multilib

DESCRIPTION="Video game music file emulators"
HOMEPAGE="https://github.com/libgme/game-music-emu"
SRC_URI="https://github.com/libgme/game-music-emu/releases/download/${PV}/libgme-${PV}-src.tar.gz"
S="${WORKDIR}/libgme-${PV}"

LICENSE="LGPL-2.1"
SLOT="0"
KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~loong ~mips ~ppc ~ppc64 ~riscv ~x86"
IUSE="test"
RESTRICT="!test? ( test )"

DEPEND="virtual/zlib:=[${MULTILIB_USEDEP}]"
RDEPEND="${DEPEND}"

DOCS=( changes.txt design.txt gme.txt readme.txt )

src_prepare() {
	cmake_src_prepare

	# do not build the demo player (also automagic with SDL2)
	cmake_comment_add_subdirectory player
}

src_configure() {
	local mycmakeargs=(
		-DENABLE_UBSAN=off # disabled so that if gcc[-sanitize] it does not fail to compile
		-DGME_BUILD_SHARED=on
		-DGME_BUILD_STATIC=off

		-DGME_BUILD_EXAMPLES=$(usex test)
		-DGME_BUILD_TESTING=$(usex test)
	)
	cmake-multilib_src_configure
}

multilib_src_compile() {
	cmake_src_compile
	use test && cmake_build demo demo_mem
}

multilib_src_test() {
	cmake_src_test -j1
}