Qt6 프로토뷰의 CMake 명령어

프로젝트에서 Qt6::Protobuf 모듈을 사용하려면 다음 CMake 명령을 호출해야 합니다:

find_package(Qt6 REQUIRED COMPONENTS Protobuf)

target_link_libraries(mytarget PRIVATE Qt6::Protobuf)

프로젝트의 Qt Protobuf 코드 생성을 암시적으로 호출하기 위해 qt_add_protobuf CMake 명령을 사용할 수 있습니다.

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)

위의 예제에서는 PROTO_FILES 옵션에 전달된 경로에 정의된 메시지 유형을 포함하는 MyMessages 라는 라이브러리를 생성합니다. GENERATE_PACKAGE_SUBFOLDERS 옵션은 생성된 파일의 폴더 구조를 생성합니다. 그리고 PROTO_INCLUDES 옵션은 지정된 디렉터리에서 종속성 또는 임포트를 찾도록 protoc에 지시합니다. MyApp 라는 실행 파일의 대상을 만들고 MyMessages 라이브러리에 링크합니다.

CMake 명령 참조도참조 하세요.

qt_add_protobuf

Qt Protobuf 스키마를 사용하여 Qt 기반 C++ 소스 코드 생성하기

© 2025 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.