Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
20qt_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
30This 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
40On all platforms except Android, an executable target will be created.
41All arguments will be passed through to the standard CMake \c{add_executable()}
42command, except \c{MANUAL_FINALIZATION} (if present). On Android, a \c{MODULE}
43library will be created and any \c{WIN32} or \c{MACOSX_BUNDLE} options will be
44ignored. 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
56Since all Qt applications need to link to the \c{Qt::Core} library, this is done
57for you as a convenience.
58
59\section2 Finalization
60
61After a target is created, further processing or \e{finalization} steps are
62commonly needed. The steps to perform depend on the platform and on various
63properties of the target.
64
65The 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
69Target finalization can occur either as part of calling \c{qt_add_executable}
70or be deferred to sometime after this command returns (but it should still be in
71the same directory scope).
72
73When using CMake 3.19 or later, target finalization is automatically deferred to the
74end of the current directory scope. This gives the caller an opportunity to
75modify properties of the created target before it is finalized. When using
76CMake versions earlier than 3.19, automatic deferral isn't supported. In that
77case, target finalization is performed immediately before this command returns.
78
79Regardless of the CMake version, the \c{MANUAL_FINALIZATION} keyword can be given to
80indicate that you will explicitly call \l{qt6_finalize_target}{qt_finalize_target()}
81yourself instead at some later time. In general, \c MANUAL_FINALIZATION should
82not be needed unless the project has to support CMake 3.18 or earlier.
83
84Project finalization occurs automatically when using CMake 3.19 or later.
85When using an older CMake version, you should call
86\l{qt6_finalize_project}{qt_finalize_project()} manually, at the end
87of the root \c CMakeLists.txt file.
88This is especially important when targeting Android, to collect dependencies
89between 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
98In the following simple case, finalization is handled automatically. If using a
99CMake version earlier than 3.19, finalization will be performed immediately as
100part of the call. When using CMake 3.19 or later, finalization will occur at the
101end of the current directory scope.
102
103\snippet cmake-macros/examples.cmake qt_add_executable_simple
104
105The following example shows a scenario where finalization must be deferred.
106The \c OUTPUT_NAME target property affects deployment settings on Android, but
107those settings are written out as part of finalizing the target. In order to
108support using CMake versions earlier than 3.19, we take over responsibility
109for 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*/