# Template file for 'protobuf'
pkgname=protobuf
version=25.2
revision=3
build_style=cmake
configure_args="-Dprotobuf_BUILD_SHARED_LIBS=ON -Dprotobuf_USE_EXTERNAL_GTEST=ON
 -Dprotobuf_BUILD_LIBPROTOC=ON -Dprotobuf_ABSL_PROVIDER=package
 -Dprotobuf_BUILD_TESTS=OFF"
# XXX: Tests require that the abseil-cpp provides absl::scoped_mock_log
hostmakedepends="pkg-config"
makedepends="zlib-devel gtest-devel abseil-cpp-devel"
short_desc="Protocol buffers compiler"
maintainer="Orphaned <orphan@voidlinux.org>"
license="BSD-3-Clause"
homepage="https://developers.google.com/protocol-buffers/"
changelog="https://raw.githubusercontent.com/google/protobuf/master/CHANGES.txt"
distfiles="https://github.com/protocolbuffers/protobuf/archive/v${version}.tar.gz"
checksum=8ff511a64fc46ee792d3fe49a5a1bcad6f7dc50dfbba5a28b0e5b979c17f9871

# Switch to versioned package
conflicts="protobuf18>=0 protobuf23>=0 protobuf24>=0
 protobuf25>=0 protobuf26>=0 protobuf28>=0"
replaces="${conflicts}"

if [ "$CROSS_BUILD" ]; then
	# needs host protoc
	hostmakedepends+=" ${pkgname}"
	configure_args+=" -Dprotobuf_PROTOC_EXE=/usr/bin/protoc"
fi

post_install() {
	vlicense LICENSE
}

libprotobuf_package() {
	short_desc="Protocol buffers C++ library"
	pkg_install() {
		vmove "usr/lib/libprotobuf.so.*"
		vlicense LICENSE
	}
}

libprotobuf-lite_package() {
	short_desc="Protocol buffers C++ library (lite version)"
	pkg_install() {
		vmove "usr/lib/libprotobuf-lite.so.*"
		vlicense LICENSE
	}
}

libprotoc_package() {
	short_desc="Protocol buffers compiler library"
	pkg_install() {
		vmove "usr/lib/libprotoc.so.*"
		vlicense LICENSE
	}
}

libprotoc-devel_package() {
	depends="libprotoc-${version}_${revision}"
	short_desc="Protocol buffers compiler library - development files"
	# Switch to versioned package
	conflicts="libprotoc18-devel>=0 libprotoc23-devel>=0
	 libprotoc24-devel>=0 libprotoc25-devel>=0
	 libprotoc26-devel>=0 libprotoc28-devel>=0"
	replaces="${conflicts}"
	pkg_install() {
		vmove usr/lib/libprotoc.so
		vmove usr/include/google/protobuf/compiler
	}
}

protobuf-devel_package() {
	depends="zlib-devel
	 libprotobuf-${version}_${revision}
	 libprotobuf-lite-${version}_${revision}
	 libprotoc-devel-${version}_${revision}
	 abseil-cpp-devel"
	short_desc="Protocol buffers C++ library - development files"
	# Switch to versioned package
	conflicts="protobuf18-devel>=0 protobuf23-devel>=0
	 protobuf24-devel>=0 protobuf25-devel>=0
	 protobuf26-devel>=0 protobuf28-devel>=0"
	replaces="${conflicts}"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/libprotobuf.so
		vmove usr/lib/libprotobuf-lite.so
		vmove usr/lib/pkgconfig
		vmove usr/lib/cmake
		# when cross-building something that uses this cmake file,
		# it barfs because it can't execute the target's protobuf binary
		vsed -i -e 's,${_IMPORT_PREFIX}/bin,/usr/bin,g' \
			"$PKGDESTDIR"/usr/lib/cmake/protobuf/protobuf-targets-none.cmake
		vmove "usr/lib/*.a"
	}
}
