diff --git a/google/cloud/storage/CMakeLists.txt b/google/cloud/storage/CMakeLists.txt index b3c2eaa890eb0..4a2b4a02a31ec 100644 --- a/google/cloud/storage/CMakeLists.txt +++ b/google/cloud/storage/CMakeLists.txt @@ -31,7 +31,14 @@ google_cloud_cpp_doxygen_targets("storage" DEPENDS cloud-docs include(GoogleCloudCppCommon) include(IncludeNlohmannJson) -find_package(Crc32c) +if (BUILD_TESTING OR absl_VERSION VERSION_LESS "20230125") + set(NEED_CRC32C TRUE) +else () + set(NEED_CRC32C FALSE) +endif () +if (NEED_CRC32C) + find_package(Crc32c REQUIRED) +endif() # Export the version information for Bazel. include(CreateBazelConfig) diff --git a/google/cloud/storage/google_cloud_cpp_storage.cmake b/google/cloud/storage/google_cloud_cpp_storage.cmake index d1fe20b4fa382..3c17c5561e098 100644 --- a/google/cloud/storage/google_cloud_cpp_storage.cmake +++ b/google/cloud/storage/google_cloud_cpp_storage.cmake @@ -273,9 +273,11 @@ target_link_libraries( google-cloud-cpp::common google-cloud-cpp::rest_internal nlohmann_json::nlohmann_json - Crc32c::crc32c CURL::libcurl Threads::Threads) +if (NEED_CRC32C) + target_link_libraries(google_cloud_cpp_storage PUBLIC Crc32c::crc32c) +endif() if (WIN32) target_compile_definitions(google_cloud_cpp_storage PRIVATE WIN32_LEAN_AND_MEAN) @@ -333,6 +335,11 @@ install( google_cloud_cpp_install_headers(google_cloud_cpp_storage include/google/cloud/storage) +set(PKGCONFIG_LIBS) +if (NEED_CRC32C) + list(APPEND PKGCONFIG_LIBS crc32c) +endif() + google_cloud_cpp_add_pkgconfig( "storage" "The Google Cloud Storage C++ Client Library" @@ -348,7 +355,7 @@ google_cloud_cpp_add_pkgconfig( NON_WIN32_REQUIRES openssl LIBS - crc32c + ${PKGCONFIG_LIBS} WIN32_LIBS ws2_32 bcrypt) diff --git a/google/cloud/storage/internal/crc32c.cc b/google/cloud/storage/internal/crc32c.cc index 57c16dfe38e20..6e8c7929c8e14 100644 --- a/google/cloud/storage/internal/crc32c.cc +++ b/google/cloud/storage/internal/crc32c.cc @@ -18,20 +18,15 @@ #include "absl/crc/crc32c.h" #define GOOGLE_CLOUD_CPP_USE_ABSL_CRC32C 1 #else +#include #define GOOGLE_CLOUD_CPP_USE_ABSL_CRC32C 0 #endif // ABSL_LTS_RELEASE_VERSION -#include namespace google { namespace cloud { namespace storage_internal { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -std::uint32_t ExtendCrc32c(std::uint32_t crc, absl::string_view data) { - return crc32c::Extend(crc, reinterpret_cast(data.data()), - data.size()); -} - std::uint32_t ExtendCrc32c(std::uint32_t crc, storage::internal::ConstBufferSequence const& data) { for (auto const& b : data) { @@ -49,6 +44,10 @@ std::uint32_t ExtendCrc32c(std::uint32_t crc, absl::Cord const& data) { #if GOOGLE_CLOUD_CPP_USE_ABSL_CRC32C +std::uint32_t ExtendCrc32c(std::uint32_t crc, absl::string_view data) { + return static_cast(absl::ExtendCrc32c(absl::crc32c_t{crc}, data)); +} + std::uint32_t ExtendCrc32c(std::uint32_t crc, absl::string_view data, std::uint32_t data_crc) { return static_cast(absl::ConcatCrc32c( @@ -71,6 +70,11 @@ std::uint32_t ExtendCrc32c(std::uint32_t crc, absl::Cord const& data, #else +std::uint32_t ExtendCrc32c(std::uint32_t crc, absl::string_view data) { + return crc32c::Extend(crc, reinterpret_cast(data.data()), + data.size()); +} + std::uint32_t ExtendCrc32c(std::uint32_t crc, absl::string_view data, std::uint32_t /*data_crc*/) { return ExtendCrc32c(crc, data);