# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Duncan Bellamy <dunk@denkimushi.com>
pkgname=abseil-cpp
pkgver=20240116.2
pkgrel=1
pkgdesc="Abseil Common Libraries (C++) "
url="https://abseil.io/"
arch="all"
license="Apache-2.0"
depends_dev="linux-headers"
makedepends="
	$depends_dev
	cmake
	gtest-dev
	samurai
	"
checkdepends="tzdata"
subpackages="$pkgname-dev"
source="https://github.com/abseil/abseil-cpp/archive/$pkgver/abseil-cpp-$pkgver.tar.gz
	0002-abseil.patch
	"

_libs="
	atomic_hook_test_helper
	bad_any_cast_impl
	bad_optional_access
	bad_variant_access
	base
	city
	civil_time
	cord
	cord_internal
	cordz_functions
	cordz_handle
	cordz_info
	cordz_sample_token
	crc32c
	crc_cord_state
	crc_cpu_detect
	crc_internal
	debugging_internal
	demangle_internal
	die_if_null
	examine_stack
	exception_safety_testing
	exponential_biased
	failure_signal_handler
	flags_commandlineflag
	flags_commandlineflag_internal
	flags_config
	flags_internal
	flags_marshalling
	flags_parse
	flags_private_handle_accessor
	flags_program_name
	flags_reflection
	flags_usage
	flags_usage_internal
	graphcycles_internal
	hash
	hash_generator_testing
	hashtablez_sampler
	int128
	kernel_timeout_internal
	leak_check
	log_entry
	log_flags
	log_globals
	log_initialize
	log_internal_check_op
	log_internal_conditions
	log_internal_fnmatch
	log_internal_format
	log_internal_globals
	log_internal_log_sink_set
	log_internal_message
	log_internal_nullguard
	log_internal_proto
	log_internal_test_actions
	log_internal_test_helpers
	log_internal_test_matchers
	log_severity
	log_sink
	low_level_hash
	malloc_internal
	per_thread_sem_test_common
	periodic_sampler
	pow10_helper
	random_distributions
	random_internal_distribution_test_util
	random_internal_platform
	random_internal_pool_urbg
	random_internal_randen
	random_internal_randen_hwaes
	random_internal_randen_hwaes_impl
	random_internal_randen_slow
	random_internal_seed_material
	random_seed_gen_exception
	random_seed_sequences
	raw_hash_set
	raw_logging_internal
	scoped_mock_log
	scoped_set_env
	spinlock_test_common
	spinlock_wait
	stack_consumption
	stacktrace
	status
	statusor
	str_format_internal
	strerror
	string_view
	strings
	strings_internal
	symbolize
	synchronization
	test_instance_tracker
	throw_delegate
	time
	time_internal_test_util
	time_zone
	vlog_config_internal
	"

for _lib in $_libs; do
	subpackages="$subpackages $pkgname-${_lib//_/-}:abseillib"
done

build() {
	cmake -B build -G Ninja \
		-DCMAKE_CXX_STANDARD=17 \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=ON \
		-DABSL_BUILD_TESTING=ON \
		-DABSL_BUILD_TEST_HELPERS=ON \
		-DABSL_USE_EXTERNAL_GOOGLETEST=ON \
		-DABSL_PROPAGATE_CXX_STD=ON \
		-DABSL_FIND_GOOGLETEST=ON
	cmake --build build
}

check() {
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest --test-dir build -E absl_str_format_convert_test
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

abseillib() {
	pkgdesc="Abseil Common C++ library: $subpkgname"

	local libname="${subpkgname#"$pkgname"-}"
	amove usr/lib/libabsl_${libname//-/_}.so.*
}

sha512sums="
5062e731ee8c9a757e6d75fc1c558652deb4dd1daab4d6143f7ad52a139501c61365f89acbf82480be0f9a4911a58286560068d8b1a8b6774e6afad51739766e  abseil-cpp-20240116.2.tar.gz
aca4f4d89c38ca9038fdeb5b9e92c68d7ce0dda79f83335238f5e8de08c1a4d1e1ddd00e9ad6da18f0ab4ee22b58d73039f5523dc9311c7dbe1998f0f59a0e58  0002-abseil.patch
"
