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

EAPI=8

inherit cmake

DESCRIPTION="C/C++ WebRTC network library featuring Data Channels, Media Transport, and WebSockets"
HOMEPAGE="https://libdatachannel.org/"

SRC_URI="https://github.com/paullouisageneau/libdatachannel/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz"

LICENSE="MPL-2.0"
SLOT="0"

KEYWORDS="amd64"

IUSE="+examples debug +websocket"

RDEPEND="dev-libs/openssl
        net-libs/usrsctp
        dev-cpp/plog
        net-libs/libnice
        net-libs/libsrtp
"
DEPEND="
	${RDEPEND}
	examples? ( dev-cpp/nlohmann_json )
"
BDEPEND="virtual/pkgconfig"

src_configure() {
        local mycmakeargs=(
		-DPREFER_SYSTEM_LIB=ON
		-DUSE_SYSTEM_SRTP=ON
		-DUSE_SYSTEM_USRSCTP=ON
		-DUSE_SYSTEM_PLOG=ON
		-DUSE_NICE=ON
        )

        if use debug; then
                mycmakeargs+=(
                        -DCMAKE_BUILD_TYPE=Debug
			-DSCTP_DEBUG=ON
                )
        fi

	if ! use examples; then
		mycmakeargs+=(
			-DNO_EXAMPLES=ON
		)
	fi
        cmake_src_configure
}