- Qt 6.10
- Qt GRPC
- CMake Commands in Qt6 GRPC
- Qt 6.10.0 Reference Documentation

The qtgrpcgen Tool ◦ qt_add_grpc

# CMake Commands in Qt6 GRPC

You should call the following CMake commands to use the Qt6::Grpc module in your project:

     find_package(Qt6 REQUIRED COMPONENTS Grpc)

     target_link_libraries(mytarget PRIVATE Qt6::Grpc)

You can use the qt_add_grpc CMake command to implicitly call Qt GRPC code generation for your project.

To generate gRPC™ services using Qt GRPC and link them with your program consider the following example:

     cmake_minimum_required(VERSION 3.16...3.22)
     project(MyProject)

     find_package(Qt6 REQUIRED COMPONENTS Protobuf Grpc)
     qt_standard_project_setup()

     qt_add_executable(MyApp main.cpp)

     qt_add_protobuf(MyApp
         PROTO_FILES
             path/to/messages.proto
     )

     qt_add_grpc(MyApp CLIENT
         PROTO_FILES
             path/to/service.proto
     )

     target_link_libraries(MyApp PRIVATE Qt6::Protobuf Qt6::Grpc)

The example above calls the `qt_add_grpc()` CMake function to start Qt GRPC code generation for `service` sections within the provided protobuf schema.

Note: If the protobuf schema also contains `message` definitions, the `qt_add_protobuf()` CMake function should also be called to start Qt Protobuf code generation.

Since we reuse the executable target, all generated files will be appended to the target, and the include directories will be updated accordingly.

See also CMake Command Reference.

qt_add_grpc | Generates Qt-based C++ services using a protobuf schema

The qtgrpcgen Tool ◦ qt_add_grpc