Protobuf generator and bindings for Qt framework

Alexey Edelev a1d2a3ecfc Make specific QML2_IMPORT_PATH for win32 build před 5 roky
3rdparty d4b0e93ab9 Tune windows build procedure před 5 roky
cmake 99b28faada Quick fix Wnd build před 5 roky
examples 99b28faada Quick fix Wnd build před 5 roky
src a1d2a3ecfc Make specific QML2_IMPORT_PATH for win32 build před 5 roky
tests a1d2a3ecfc Make specific QML2_IMPORT_PATH for win32 build před 5 roky
.gitignore 7495ae7751 Initial version of generator před 6 roky
.gitmodules d4b0e93ab9 Tune windows build procedure před 5 roky
CMakeLists.txt 1f62e52a88 Fix linking issue před 5 roky
Doxyfile.in a29546b851 Unify doxy comments style před 5 roky
LICENSE 3beab4ea24 Implement move semantic for generated classes, update copyrights. před 6 roky
ProjectConfig.cmake.in b289fe37b4 Fix cmake dependencies for file generation před 5 roky
README.md 6e2b0a480d Update Usage chapter in Readme před 5 roky

README.md

QtProtobuf

Protobuf plugin to generate Qt classes

Linux Build

Prerequesties

Check installation of protobuf and grpc in your system. Minimum required versions are protobuf-3.6.0 and grpc-1.15.0.

Note: Older versions could be supported as well but not officially tested.

All-in-one build

If required versions of libraries are not found in your system, you may use all-in-one build procedure for prerequesties

Update submodules to fetch 3rdparty dependencies:

git submodule update --init --recursive

Build

mkdir build
cd build
cmake ..
cmake --build . [--config <RELEASE|DEBUG>] -- -j<N>

Windows Build

Prerequesties

Download and install:

  • Qt 5.12.3 or higher 1
  • cmake-3.1 or higher 2
  • Strawberry perl 5.28 3
  • GoLang 1.10 or higher 4
  • Yasm 1.3 or higher 5
  • Actual Visual Studio Compiler with cmake support that required by Qt 6

Note: All applications should be in PATH

Update submodules to fetch 3rdparty dependencies:

git submodule update --init --recursive

Build

Open Qt MSVC command line and follow steps:

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x86
cd <directory with qtprotobuf project>
mkdir build
cd build
cmake ..
cmake --build . [--config <RELEASE|DEBUG>] -- /m:<N>

Note: 64-bit build is not supported yet

Usage

Direct usage of generator

protoc --plugin=protoc-gen-qtprotobuf=<path/to/bin>/qtprotobufgen --qtprotobuf_out=<output_dir> <protofile>.proto [--qtprotobuf_opt=out=<output_dir>]

Integration with project

You can integrate QtProtobuf as submodule in your project or as installed in system package. Add following line in your project CMakeLists.txt:

...
find_package(QtProtobufProject CONFIG REQUIRED COMPONENTS QtProtobuf QtGrpc)
set(GENERATED_HEADERS
    # List of artifacts expected after qtprotobufgen job done.
    # Usually it's full list of messages in all packages with .h header suffix
    ...
    )
file(GLOB PROTO_FILES ABSOLUTE ${CMAKE_CURRENT_SOURCE_DIR}/path/to/protofile1.proto
                               ${CMAKE_CURRENT_SOURCE_DIR}/path/to/protofile2.proto
                               ...
                               ${CMAKE_CURRENT_SOURCE_DIR}/path/to/protofileN.proto)
# Function below generates source files for specified PROTO_FILES,
# writes result to STATIC library target and saves its name to 
# ${QtProtobuf_GENERATED} variable
generate_qtprotobuf(TARGET MyTarget
    OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated
    PROTO_FILES ${PROTO_FILES}
    GENERATED_HEADERS ${GENERATED_HEADERS})
add_executable(MyTarget main.cpp) # Add your target here
target_link_libraries(MyTarget ${QtProtobuf_GENERATED})

CMake functions reference

generate_qtprotobuf

generate_qtprotobuf is cmake helper function that automatically generates STATIC library target from your .proto files

Due to cmake restrictions it's required to specify resulting artifacts manually as list of header files expected after generator job finished.

Parameters:

TARGET - name of you target that will be base for generated target name

OUT_DIR - output directory that will contain generated artifacts. Usually subfolder in build directory should be used

GENERATED_HEADERS - List of header files expected after generator job finished

PROTO_FILES - List of .proto files that will be used in generation procedure

Outcome:

QtProtobuf_GENERATED - variable that will contain generated STATIC library target name

Running tests

cd <build directory>
ctest

Documentation generation

Project uses doxygen for documentation generation.

For Windows additionally install:

You can generate documentation:

mkdir build
cd build
cmake ..
cmake --build . --target doc