[build] Make Protobuf optional in CMake build (#7061)

This commit is contained in:
Tyler Veness
2024-09-12 23:44:19 -07:00
committed by GitHub
parent b9409a4bcf
commit d44b651558
77 changed files with 168 additions and 73 deletions

View File

@@ -14,8 +14,6 @@
#include <vector>
#include <fmt/format.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/message.h>
#include <imgui.h>
#include <imgui_stdlib.h>
#include <networktables/NetworkTableInstance.h>
@@ -31,6 +29,11 @@
#include <wpi/print.h>
#include <wpi/raw_ostream.h>
#ifndef NO_PROTOBUF
#include <google/protobuf/descriptor.h>
#include <google/protobuf/message.h>
#endif
#include "glass/Context.h"
#include "glass/DataSource.h"
#include "glass/Storage.h"
@@ -346,6 +349,7 @@ static void UpdateStructValueSource(NetworkTablesModel& model,
}
}
#ifndef NO_PROTOBUF
static void UpdateProtobufValueSource(NetworkTablesModel& model,
NetworkTablesModel::ValueSource* out,
const google::protobuf::Message& msg,
@@ -534,6 +538,7 @@ static void UpdateProtobufValueSource(NetworkTablesModel& model,
}
}
}
#endif
static void UpdateJsonValueSource(NetworkTablesModel& model,
NetworkTablesModel::ValueSource* out,
@@ -764,6 +769,7 @@ void NetworkTablesModel::ValueSource::UpdateFromValue(
valueChildren.clear();
}
} else if (auto filename = wpi::remove_prefix(typeStr, "proto:")) {
#ifndef NO_PROTOBUF
auto msg = model.m_protoDb.Find(*filename);
if (msg) {
msg->Clear();
@@ -777,6 +783,9 @@ void NetworkTablesModel::ValueSource::UpdateFromValue(
} else {
valueChildren.clear();
}
#else
valueChildren.clear();
#endif
} else {
valueChildren.clear();
}
@@ -902,6 +911,7 @@ void NetworkTablesModel::Update() {
wpi::remove_prefix(entry->info.name, "/.schema/proto:");
entry->value.IsRaw() && filename &&
entry->info.type_str == "proto:FileDescriptorProto") {
#ifndef NO_PROTOBUF
// protobuf descriptor handling
if (!m_protoDb.Add(*filename, entry->value.GetRaw())) {
wpi::print("could not decode protobuf '{}' filename '{}'\n",
@@ -918,6 +928,7 @@ void NetworkTablesModel::Update() {
}
}
}
#endif
}
}
}