1.7 KiB
1.7 KiB
Protocol Buffers (Protobuf) Integration
This project supports optional Protocol Buffers integration via vcpkg.
Installation
Install protobuf via vcpkg:
vcpkg install protobuf[zlib] protobuf[zlib]:x64-windows
CMake Configuration
Option 1: Using vcpkg Toolchain (Recommended)
When configuring CMake, specify the vcpkg toolchain file:
cmake -S applications -B build --toolchain [path to vcpkg]/scripts/buildsystems/vcpkg.cmake
Or set it as an environment variable:
$env:CMAKE_TOOLCHAIN_FILE = "[path to vcpkg]/scripts/buildsystems/vcpkg.cmake"
cmake -S applications -B build
Option 2: Disable Protobuf (if not needed)
cmake -S applications -B build -DENABLE_PROTOBUF=OFF
CMake Options
ENABLE_PROTOBUF(default:ON) - Enable or disable Protocol Buffers support
Usage in Code
When protobuf is enabled, the ENABLE_PROTOBUF preprocessor macro is defined:
#ifdef ENABLE_PROTOBUF
#include <google/protobuf/...>
// Use protobuf APIs
#else
// Fallback code when protobuf is disabled
#endif
Targets
All executables automatically link to protobuf when available:
nodehubnodehub-consolecore_tests
Protobuf is linked via the protobuf_interface interface library, which provides:
protobuf::libprotobuf- Main protobuf libraryprotobuf::libprotoc- Protocol compiler libraryENABLE_PROTOBUF=1compile definition