IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

CMake Commands in Qt6 Protobuf

Qt Protobuf Reference Documentation.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

CMake Commands in Qt6 Protobuf

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

 
Sélectionnez
find_package(Qt6 REQUIRED COMPONENTS Protobuf)

target_link_libraries(mytarget PRIVATE Qt6::Protobuf)

You can use qt-add-protobuf CMake macros. The macros implicitly calls Protobuf code generation for qt-project.

The macros usage example:

 
Sélectionnez
cmake_minimum_required(VERSION 3.16...3.22)
project(MyThings)

find_package(Qt6 REQUIRED COMPONENTS Protobuf)
qt_standard_project_setup()

qt_add_protobuf(MyMessages
    GENERATE_PACKAGE_SUBFOLDERS
    PROTO_FILES
        path/to/message.proto
        path/to/other_message.proto
    PROTO_INCLUDES
        /path/to/proto/include
)

qt_add_executable(MyApp main.cpp)

target_link_libraries(MyApp PRIVATE MyMessages)

In the example above we generate a library called MyMessages which contains the message types defined in the paths passed to the PROTO_FILES option. We use the GENERATE_PACKAGE_SUBFOLDERS option to generate a folder structure for the generated files. And the PROTO_INCLUDES option tells protoc to look for dependencies/imports in the specified directories.

We then create a target for an executable called MyApp which we link to the MyMessages library.

See Also

Contents

  • qt_add_protobuf: Generates Qt-based C++ source code using a protobuf schema

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+