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.
44
45
With the target-based signature, generated files are added as sources to
46
\c{<TARGET>}. With the older signature, the paths of the generated files are
47
added to \c{<VAR>}.
48
49
\note This is a low-level macro. See the \l{CMake AUTOMOC Documentation} for a
50
more convenient way to let source files be processed with \c{moc}.
51
52
\section1 Arguments
53
54
You can set an explicit \c{TARGET}. This will make sure that the target
55
properties \c{INCLUDE_DIRECTORIES} and \c{COMPILE_DEFINITIONS} are also used
56
when scanning the source files with \c{moc}.
57
58
Since Qt 6.8, when a source file is passed to \c{qt_wrap_cpp} instead of a
59
header file to generate a \c{.moc} file for a target, the \c{TARGET} parameter
60
is needed to set the correct include path for the generated \c{.moc} file in
61
the source file.
62
63
If you're calling \c qt_wrap_cpp in a directory scope that's different from the
64
directory scope of the target, you must use the target-based signature of \c
65
qt_wrap_cpp or pass the target with the \c TARGET argument.
66
67
You can set additional \c{OPTIONS} that should be added to the \c{moc} calls.
68
You can find possible options in the \l{moc}{moc documentation}.
69
70
The \c{OPTIONS} can evaluate generator expressions when \c{TARGET} is set.
71
\note If the \c{OPTIONS} include both generator expressions and special
72
characters, use variables to implement them. For example, use \c{$<ANGLE-R>},
73
\c{$<COMMA>} and \c{$<SEMICOLON>} instead of \c{>}, \c{,} and \c{:}. Otherwise,
74
the generator expression will not be evaluated correctly. \c {OPTIONS} are
75
wrapped in generator expressions, so you must escape special characters in
76
them.
77
78
\c{DEPENDS} allows you to add additional dependencies for recreation of the
79
generated files. This is useful when the sources have implicit dependencies,
80
like code for a Qt plugin that includes a \c{.json} file using the
81
Q_PLUGIN_METADATA() macro.
82
83
\section1 Examples
84
85
Since Qt 6.8:
86
87
\snippet cmake-macros/examples.cmake qt_wrap_cpp_4
88
\br
89
\snippet cmake-macros/examples.cpp qt_wrap_cpp_4
90
91
In the above file, \c{myapp.moc} is included in \c{myapp.cpp}.
92
To generate the \c{myapp.moc} file, the \c{qt_wrap_cpp} macro is used with the
93
\c{TARGET} parameter. The \c{.moc} file and its path will be added to the
94
target's sources and include directories by the \c{qt_wrap_cpp} macro.
95
96
The old version:
97
\snippet cmake-macros/examples.cmake qt_wrap_cpp_1
98
99
In the following example, the generator expressions passed to \c{OPTIONS}
100
will be evaluated since \c{TARGET} is set. The argument is specified this way to
101
avoid syntax errors in the generator expressions.
102
103
\snippet cmake-macros/examples.cmake qt_wrap_cpp_2
104
105
The following example uses \l{https://cmake.org/cmake/help/latest/command/target_compile_definitions.html}{target_compile_definitions}
106
to set \l{https://cmake.org/cmake/help/latest/prop_tgt/COMPILE_DEFINITIONS.html}{COMPILE_DEFINITIONS} which will be added to
107
\c{OPTIONS}.
108
\snippet cmake-macros/examples.cmake qt_wrap_cpp_3
109
110
*/
qtbase
src
corelib
doc
src
cmake
qt_wrap_cpp.qdoc
Generated on
for Qt by
1.16.1