SUMMARY="A C++ Matrix Client Library"
DESCRIPTION="mtxclient is a C++ library implementing the Matrix protocol"
HOMEPAGE="https://github.com/Nheko-Reborn/mtxclient"
COPYRIGHT="2018 Konstantinos Sideris"
LICENSE="MIT"
REVISION="2"
SOURCE_URI="https://github.com/Nheko-Reborn/mtxclient/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="9478d870296ebe7679c90f563cb798eb3cdd3f9c4578ceea5af75b66f456baaa"
SOURCE_FILENAME="mtxclient-v$portVersion.tar.gz"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

libVersion="$portVersion"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"

boostMinimumVersion="1.70.0"

PROVIDES="
	mtxclient$secondaryArchSuffix = $portVersion
	lib:libmatrix_client$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libboost_iostreams$secondaryArchSuffix
	lib:libboost_system$secondaryArchSuffix
	lib:libboost_thread$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libolm$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	"

PROVIDES_devel="
	mtxclient${secondaryArchSuffix}_devel = $portVersion
	devel:libmatrix_client$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	mtxclient$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:nlohmann_json
	devel:libboost_iostreams$secondaryArchSuffix >= $boostMinimumVersion
	devel:libboost_system$secondaryArchSuffix >= $boostMinimumVersion
	devel:libboost_thread$secondaryArchSuffix >= $boostMinimumVersion
	devel:libolm$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	cmake $cmakeDirArgs -Bbuild -S. \
		-DCMAKE_BUILD_TYPE=Release \
		-DBUILD_LIB_TESTS=OFF \
		-DBUILD_LIB_EXAMPLES=OFF
	make -C build $jobArgs
}

INSTALL()
{
	make -C build install

	prepareInstalledDevelLib libmatrix_client
	fixPkgconfig

	#fixCmake
	sed -i 's,\/include,/'${relativeIncludeDir}',g' \
		$libDir/cmake/MatrixClient/MatrixClientTargets.cmake

	# devel package
	packageEntries devel \
		"$developDir" \
		"$libDir"/cmake
}
