Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qt_wrap_cpp.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2020 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\page qt-wrap-cpp.html
6
\ingroup cmake-commands-qtcore
7
8
\title qt_wrap_cpp
9
\keyword qt6_wrap_cpp
10
11
\summary {Creates .moc files from sources.}
12
13
\include cmake-find-package-core.qdocinc
14
15
\cmakecommandsince 5.0
16
17
\section1 Synopsis
18
19
\c{qt_wrap_cpp} supports two signatures. The first signature was added in Qt 6.8
20
and has the following form:
21
22
\badcode
23
qt_wrap_cpp(<TARGET> src_file1 [src_file2 ...]
24
[OPTIONS ...]
25
[DEPENDS ...])
26
\endcode
27
28
\note The signature above is recommended over the older signature.
29
30
\badcode
31
qt_wrap_cpp(<VAR> src_file1 [src_file2 ...]
32
[TARGET target]
33
[OPTIONS ...]
34
[DEPENDS ...])
35
\endcode
36
37
\versionlessCMakeCommandsNote qt6_wrap_cpp()
38
39
\section1 Description
40
41
Creates rules for calling the \l{moc}{Meta-Object Compiler (moc)} on the given
42
source files. For each input file, an output file is generated in the build
43
directory. The paths of the generated files are added to \c{<VAR>}.
44
45
\note This is a low-level macro. See the \l{CMake AUTOMOC Documentation} for a
46
more convenient way to let source files be processed with \c{moc}.
47
48
\section1 Arguments
49
50
You can set an explicit \c{TARGET}. This will make sure that the target
51
properties \c{INCLUDE_DIRECTORIES} and \c{COMPILE_DEFINITIONS} are also used
52
when scanning the source files with \c{moc}.
53
54
Since Qt 6.8, when a source file is passed to \c{qt_wrap_cpp} instead of a
55
header file to generate a \c{.moc} file for a target, the \c{TARGET} parameter
56
is needed to set the correct include path for the generated \c{.moc} file in
57
the source file. As generated \c{.moc} files are added to the target's
58
sources by \c{qt_wrap_cpp}, they are not added to \c{<VAR>}.
59
60
You can set additional \c{OPTIONS} that should be added to the \c{moc} calls.
61
You can find possible options in the \l{moc}{moc documentation}.
62
63
The \c{OPTIONS} can evaluate generator expressions when \c{TARGET} is set.
64
\note If the \c{OPTIONS} include both generator expressions and special
65
characters, use variables to implement them. For example, use \c{$<ANGLE-R>},
66
\c{$<COMMA>} and \c{$<SEMICOLON>} instead of \c{>}, \c{,} and \c{:}. Otherwise,
67
the generator expression will not be evaluated correctly. \c {OPTIONS} are
68
wrapped in generator expressions, so you must escape special characters in
69
them.
70
71
\c{DEPENDS} allows you to add additional dependencies for recreation of the
72
generated files. This is useful when the sources have implicit dependencies,
73
like code for a Qt plugin that includes a \c{.json} file using the
74
Q_PLUGIN_METADATA() macro.
75
76
\section1 Examples
77
78
Since Qt 6.8:
79
80
\snippet cmake-macros/examples.cmake qt_wrap_cpp_4
81
\br
82
\snippet cmake-macros/examples.cpp qt_wrap_cpp_4
83
84
In the above file, \c{myapp.moc} is included in \c{myapp.cpp}.
85
To generate the \c{myapp.moc} file, the \c{qt_wrap_cpp} macro is used with the
86
\c{TARGET} parameter. The \c{.moc} file and its path will be added to the
87
target's sources and include directories by the \c{qt_wrap_cpp} macro.
88
89
The old version:
90
\snippet cmake-macros/examples.cmake qt_wrap_cpp_1
91
92
In the following example, the generator expressions passed to \c{OPTIONS}
93
will be evaluated since \c{TARGET} is set. The argument is specified this way to
94
avoid syntax errors in the generator expressions.
95
96
\snippet cmake-macros/examples.cmake qt_wrap_cpp_2
97
98
The following example uses \l{https://cmake.org/cmake/help/latest/command/target_compile_definitions.html}{target_compile_definitions}
99
to set \l{https://cmake.org/cmake/help/latest/prop_tgt/COMPILE_DEFINITIONS.html}{COMPILE_DEFINITIONS} which will be added to
100
\c{OPTIONS}.
101
\snippet cmake-macros/examples.cmake qt_wrap_cpp_3
102
103
*/
qtbase
src
corelib
doc
src
cmake
qt_wrap_cpp.qdoc
Generated on
for Qt by
1.14.0