deargui-vpl/docs/cmake-protobuf.md
2026-02-03 18:25:25 +01:00

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

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:

  • nodehub
  • nodehub-console
  • core_tests

Protobuf is linked via the protobuf_interface interface library, which provides:

  • protobuf::libprotobuf - Main protobuf library
  • protobuf::libprotoc - Protocol compiler library
  • ENABLE_PROTOBUF=1 compile definition

References