Qt6 Protobuf における CMake コマンド
プロジェクトで Qt6::Protobuf モジュールを使用するには、以下の CMake コマンドを実行する必要があります:
find_package(Qt6 REQUIRED COMPONENTS Protobuf)
target_link_libraries(mytarget PRIVATE Qt6::Protobuf)qt_add_protobufCMake コマンドを使用すると、プロジェクトに対してQt Protobuf のコード生成を暗黙的に呼び出すことができます。
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)上記の例では、`MyMessages` という名前のライブラリを生成します。このライブラリには、`PROTO_FILES ` オプションに渡されたパスで定義されたメッセージ型が含まれます。`GENERATE_PACKAGE_SUBFOLDERS ` オプションは、生成されたファイル用のフォルダ構造を生成します。また、`PROTO_INCLUDES ` オプションは、protoc に指定されたディレクトリ内で依存関係やインポートを検索するよう指示します。MyApp という名前の実行ファイル用のターゲットを作成し、これを `MyMessages ` ライブラリにリンクします。
「CMake コマンドリファレンス」も参照してください 。
protobufスキーマを使用して、QtベースのC++ソースコードを生成します。 |
© 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.