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_add_executable.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-add-executable.html
6
\ingroup cmake-commands-qtcore
7
8
\title qt_add_executable
9
\keyword qt6_add_executable
10
11
\summary {Creates and finalizes an application target of a platform-specific type.}
12
13
\include cmake-find-package-core.qdocinc
14
15
\cmakecommandsince 6.0
16
17
\section1 Synopsis
18
19
\badcode
20
qt_add_executable(target
21
[WIN32] [MACOSX_BUNDLE]
22
[MANUAL_FINALIZATION]
23
sources...)
24
\endcode
25
26
\versionlessCMakeCommandsNote qt6_add_executable()
27
28
\section1 Description
29
30
This command performs the following tasks:
31
32
\list
33
\li Create a CMake target of the appropriate type for the target platform.
34
\li Link the target to the \c{Qt::Core} library.
35
\li Handle finalization of the CMake target.
36
\endlist
37
38
\section2 Target Creation
39
40
On all platforms except Android, an executable target will be created.
41
All arguments will be passed through to the standard CMake \c{add_executable()}
42
command, except \c{MANUAL_FINALIZATION} (if present). On Android, a \c{MODULE}
43
library will be created and any \c{WIN32} or \c{MACOSX_BUNDLE} options will be
44
ignored. Some target properties will also be set for Android:
45
46
\list
47
\li The \c{SUFFIX} target property will be set to give the library file name an
48
architecture-specific suffix.
49
\li Various \c{<lang>_VISIBILITY_PRESET} target properties will be set to
50
\c{default} to ensure that the \c{main()} function is visible in the
51
resultant binary.
52
\endlist
53
54
\section2 Linking Qt::Core
55
56
Since all Qt applications need to link to the \c{Qt::Core} library, this is done
57
for you as a convenience.
58
59
\section2 Finalization
60
61
After a target is created, further processing or \e{finalization} steps are
62
commonly needed. The steps to perform depend on the platform and on various
63
properties of the target.
64
65
The finalization processing is implemented by two commands:
66
\l{qt6_finalize_target}{qt_finalize_target()} and
67
\l{qt6_finalize_project}{qt_finalize_project()}.
68
69
Target finalization can occur either as part of calling \c{qt_add_executable}
70
or be deferred to sometime after this command returns (but it should still be in
71
the same directory scope).
72
73
When using CMake 3.19 or later, target finalization is automatically deferred to the
74
end of the current directory scope. This gives the caller an opportunity to
75
modify properties of the created target before it is finalized. When using
76
CMake versions earlier than 3.19, automatic deferral isn't supported. In that
77
case, target finalization is performed immediately before this command returns.
78
79
Regardless of the CMake version, the \c{MANUAL_FINALIZATION} keyword can be given to
80
indicate that you will explicitly call \l{qt6_finalize_target}{qt_finalize_target()}
81
yourself instead at some later time. In general, \c MANUAL_FINALIZATION should
82
not be needed unless the project has to support CMake 3.18 or earlier.
83
84
Project finalization occurs automatically when using CMake 3.19 or later.
85
When using an older CMake version, you should call
86
\l{qt6_finalize_project}{qt_finalize_project()} manually, at the end
87
of the root \c CMakeLists.txt file.
88
This is especially important when targeting Android, to collect dependencies
89
between project targets for deployment purposes.
90
91
\sa {qt6_finalize_target}{qt_finalize_target()},
92
{qt6_set_finalizer_mode}{qt_set_finalizer_mode()},
93
{qt6_add_library}{qt_add_library()},
94
{qt6_finalize_project}{qt_finalize_project()}
95
96
\section1 Examples
97
98
In the following simple case, finalization is handled automatically. If using a
99
CMake version earlier than 3.19, finalization will be performed immediately as
100
part of the call. When using CMake 3.19 or later, finalization will occur at the
101
end of the current directory scope.
102
103
\snippet cmake-macros/examples.cmake qt_add_executable_simple
104
105
The following example shows a scenario where finalization must be deferred.
106
The \c OUTPUT_NAME target property affects deployment settings on Android, but
107
those settings are written out as part of finalizing the target. In order to
108
support using CMake versions earlier than 3.19, we take over responsibility
109
for finalizing the target by adding the \c{MANUAL_FINALIZATION} keyword.
110
111
\snippet cmake-macros/examples.cmake qt_add_executable_deferred
112
113
\include cmake-android-qt-finalize-project-warning.qdocinc warning
114
*/
qtbase
src
corelib
doc
src
cmake
qt_add_executable.qdoc
Generated on
for Qt by
1.14.0