nmeum / android-tools

Unoffical CMake-based build system for android command line utilities
Apache License 2.0
176 stars 51 forks source link

vendor/extras: Fix building with newer protobuf versions #120

Closed Biswa96 closed 1 year ago

Biswa96 commented 1 year ago

Fixes https://github.com/nmeum/android-tools/issues/119

munix9 commented 1 year ago

So the whole locally tested patch looks like this:

diff -ruN a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt
--- a/vendor/CMakeLists.txt
+++ b/vendor/CMakeLists.txt
@@ -73,6 +73,8 @@
 pkg_check_modules(libzstd REQUIRED IMPORTED_TARGET libzstd)

+find_package(Protobuf CONFIG)
 find_package(Protobuf REQUIRED)
+set(PROTOBUF_LIBRARIES protobuf::libprotobuf)
 set(THREADS_PREFER_PTHREAD_FLAG ON)
 find_package(Threads REQUIRED)

diff -ruN a/vendor/extras/libjsonpb/parse/jsonpb.cpp b/vendor/extras/libjsonpb/parse/jsonpb.cpp
--- a/vendor/extras/libjsonpb/parse/jsonpb.cpp
+++ b/vendor/extras/libjsonpb/parse/jsonpb.cpp
@@ -50,8 +50,10 @@
   if (!status.ok()) {
 #if GOOGLE_PROTOBUF_VERSION < 3016000
     return MakeError<std::string>(status.error_message().as_string());
-#else
+#elif GOOGLE_PROTOBUF_VERSION < 4022000
     return MakeError<std::string>(status.message().as_string());
+#else
+    return MakeError<std::string>(std::string(status.message()));
 #endif
   }
   return ErrorOr<std::string>(std::move(json));
@@ -67,8 +69,10 @@
   if (!status.ok()) {
 #if GOOGLE_PROTOBUF_VERSION < 3016000
     return MakeError<std::monostate>(status.error_message().as_string());
-#else
+#elif GOOGLE_PROTOBUF_VERSION < 4022000
     return MakeError<std::monostate>(status.message().as_string());
+#else
+    return MakeError<std::monostate>(std::string(status.message()));
 #endif
   }
   if (!message->ParseFromString(binary)) {

Tested in openSUSE Tumbleweed with protobuf 21.12 (old) and 22.5 (new).