Commandes CMake dans Qt6 Protobuf
Vous devez exécuter les commandes CMake suivantes pour utiliser le module Qt6::Protobuf dans votre projet :
find_package(Qt6 REQUIRED COMPONENTS Protobuf)
target_link_libraries(mytarget PRIVATE Qt6::Protobuf)Vous pouvez utiliser la commande CMake ` qt_add_protobuf ` pour déclencher implicitement la génération de code par l Qt Protobuf.
Utilisation de qt_add_protobuf
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)Dans l’exemple ci-dessus, nous générons une bibliothèque nommée ` MyMessages`, qui contient les types de messages définis dans les chemins passés à l’option ` PROTO_FILES `. L’option ` GENERATE_PACKAGE_SUBFOLDERS ` permet de générer une structure de dossiers pour les fichiers générés. Enfin, l’option ` PROTO_INCLUDES ` indique à protoc de rechercher les dépendances ou les importations dans les répertoires spécifiés. Nous créons une cible pour un exécutable nommé ` MyApp`, que nous lions à la bibliothèque ` MyMessages `.
Voir également la référence des commandes CMake.
Génère du code source C++ basé sur Qt à partir d’un schéma Protobuf. |
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.