Creates .moc files from sources.
命令的定义在
核心
组件对于
Qt6
包,可以像这样加载:
find_package(Qt6 REQUIRED COMPONENTS Core)
该命令在 Qt 5.0 引入。
qt_wrap_cpp(<VAR> src_file1 [src_file2 ...] [TARGET target] [OPTIONS ...] [DEPENDS ...])
若
无版本命令
被禁用,使用
qt6_wrap_cpp()
代替。它支持如此命令的一组相同自变量。
Creates rules for calling the
MOC (元对象编译器)
on the given source files. For each input file, an output file is generated in the build directory. The paths of the generated files are added to
<VAR>
.
注意:
This is a low-level macro. See the
CMake AUTOMOC Documentation
for a more convenient way to let source files be processed with
moc
.
可以明确设置
TARGET
. This will make sure that the target properties
INCLUDE_DIRECTORIES
and
COMPILE_DEFINITIONS
are also used when scanning the source files with
moc
.
可以设置额外
选项
应该被添加到
moc
调用。可以查找可能的选项在
moc documentation
.
DEPENDS
allows you to add additional dependencies for recreation of the generated files. This is useful when the sources have implicit dependencies, like code for a Qt plugin that includes a
.json
文件使用
Q_PLUGIN_METADATA
() 宏。
set(SOURCES myapp.cpp main.cpp) qt_wrap_cpp(SOURCES myapp.h) qt_add_executable(myapp ${SOURCES})