qt_generate_wayland_protocol_client_sources
为 Wayland 协议的 .XML 文件生成客户端侧的 C++ 绑定代码。
该命令定义在Qt6 包的WaylandClient 组件中,可按以下方式加载:
find_package(Qt6 REQUIRED COMPONENTS WaylandClient)该命令首次引入于 Qt 6.0。
语法
qt_generate_wayland_protocol_client_sources(target
[PUBLIC_CODE | PRIVATE_CODE]
[NO_INCLUDE_CORE_ONLY]
FILES file1.xml [file2.xml ...])如果禁用了无版本命令,请改用qt6_generate_wayland_protocol_client_sources() 。它支持与本命令相同的参数集。
描述
qt_generate_wayland_protocol_client_sources() 会生成构建步骤,用于对一个或多个 Wayland 协议文件运行wayland-scanner 和qtwaylandscanner 。这些工具将进而生成用于实现协议的 C 和 C++ 绑定代码,生成的文件将作为target 的一部分进行构建。
选项PUBLIC_CODE 和PRIVATE_CODE (在 Qt 6.8 中新增)分别对应于wayland-scanner 中的public-code 和private-code 选项。PUBLIC_CODE 将导致由wayland-scanner 生成的代码中的符号被导出。
在 Qt 6.12 之前,默认值为PUBLIC_CODE 。对于 Qt 6.12 及更高版本,如果 Qt 策略qt_cmake_policy_qtp0006设置为NEW ,则默认值为PRIVATE_CODE 。通常强烈建议使用PRIVATE_CODE 。
默认情况下,wayland-scanner 会带--include-core-only 参数被调用,以确保生成的代码包含"wayland-client-core.h" 。可以通过使用NO_INCLUDE_CORE_ONLY 选项禁用此行为,该选项将包含路径切换为"wayland-client.h" 。
注意: 通常不建议使用 NO_INCLUDE_CORE_ONLY 。"wayland-client.h" 包含核心 Wayland 协议的预编译版本,这可能会与较新的协议版本或其他头文件(如旧版本的 Vulkan)发生冲突。仅当您对核心头文件中未包含的类型有特定需求,并且清楚了解潜在的构建时冲突时,才应使用此选项。
qt_generate_wayland_protocol_client_sources() 将触发生成实现协议客户端所需的文件。qt_generate_wayland_protocol_server_sources()是用于合成器的等效函数。
有关如何使用这些函数的示例,请参阅“自定义 Shell”或“自定义扩展”示例。
© 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.