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

EAPI=8
inherit cmake

DESCRIPTION="C++ frame profiler"
HOMEPAGE="https://github.com/wolfpld/tracy"
SRC_URI="https://github.com/wolfpld/${PN}/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz"

LICENSE="BSD"
SLOT="0"
KEYWORDS="~amd64"

DEPEND="dev-libs/capstone
	media-libs/freetype
	media-libs/glfw"
RDEPEND="${DEPEND}"

src_prepare() {
	# Upstream appends $<CONFIG> to the lib install destination for
	# non-Release builds, which lands the library in /usr/lib64/RelWithDebInfo/
	# under Gentoo's default CMAKE_BUILD_TYPE.
	sed -re 's|/\$<IF:\$<CONFIG:Release>,,\$<CONFIG>>||g' -i CMakeLists.txt || die
	cmake_src_prepare
}

src_configure() {
	# Profiling is opt-in: nothing runs until the consumer calls
	# tracy::StartupProfiler(), and nothing is collected until a viewer
	# connects. Tracy's crash handler is off because emulators handle SIGSEGV.
	local mycmakeargs=(
		-DTRACY_ENABLE=ON
		-DTRACY_MANUAL_LIFETIME=ON
		-DTRACY_NO_CRASH_HANDLER=ON
		-DTRACY_ON_DEMAND=ON
	)
	cmake_src_configure
}