Commandes CMake dans Qt6 Protobuf
Vous devez appeler 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 appeler implicitement la génération de code Qt Protobuf pour votre projet.
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 appelé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 dossier pour les fichiers générés. L'option PROTO_INCLUDES indique à protoc de rechercher des dépendances ou des importations dans les répertoires spécifiés. Nous créons une cible pour un exécutable appelé 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 à l'aide 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.