summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/src/cmake/qt_add_executable.qdoc
blob: a09ecc8dfd2f4d49e0fe9a721d1bdebc2c446b23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
\page qt_add_executable.html
\ingroup cmake-commands-qtcore

\title qt_add_executable
\target qt6_add_executable

\summary {Creates and finalizes an application target of a platform-specific type.}

\include cmake-find-package-core.qdocinc

\cmakecommandsince 6.0

\section1 Synopsis

\badcode
qt_add_executable(target
                  [WIN32] [MACOSX_BUNDLE]
                  [MANUAL_FINALIZATION]
                  sources...)
\endcode

\versionlessCMakeCommandsNote qt6_add_executable()

\section1 Description

This command performs the following tasks:

\list
\li Create a CMake target of the appropriate type for the target platform.
\li Link the target to the \c{Qt::Core} library.
\li Handle finalization of the CMake target.
\endlist

\section2 Target Creation

On all platforms except Android, an executable target will be created.
All arguments will be passed through to the standard CMake \c{add_executable()}
command, except \c{MANUAL_FINALIZATION} (if present). On Android, a \c{MODULE}
library will be created and any \c{WIN32} or \c{MACOSX_BUNDLE} options will be
ignored. Some target properties will also be set for Android:

\list
\li The \c{SUFFIX} target property will be set to give the library file name an
    architecture-specific suffix.
\li Various \c{<lang>_VISIBILITY_PRESET} target properties will be set to
    \c{default} to ensure that the \c{main()} function is visible in the
    resultant binary.
\endlist

\section2 Linking Qt::Core

Since all Qt applications need to link to the \c{Qt::Core} library, this is done
for you as a convenience.

\section2 Finalization

After a target is created, further processing or \e{finalization} steps are
commonly needed. The steps to perform depend on the platform and on various
properties of the target. The finalization processing is implemented by the
\l{qt6_finalize_target}{qt_finalize_target()} command. You might need to also
call the \l{qt6_finalize_project}{qt_finalize_project()} command at the end
of top-level CMakeLists.txt to correctly resolve the dependencies between
project targets.

Finalization can occur either as part of this call or be deferred to sometime
after this command returns (but it should still be in the same directory scope).
When using CMake 3.19 or later, finalization is automatically deferred to the
end of the current directory scope. This gives the caller an opportunity to
modify properties of the created target before it is finalized. When using
CMake versions earlier than 3.19, automatic deferral isn't supported. In that
case, finalization is performed immediately before this command returns.

Regardless of the CMake version, the \c{MANUAL_FINALIZATION} keyword can be given to
indicate that you will explicitly call \l{qt6_finalize_target}{qt_finalize_target()}
yourself instead at some later time. In general, \c MANUAL_FINALIZATION should
not be needed unless the project has to support CMake 3.18 or earlier.

\sa {qt6_finalize_target}{qt_finalize_target()},
    {qt6_set_finalizer_mode}{qt_set_finalizer_mode()},
    {qt6_add_library}{qt_add_library()},
    {qt6_finalize_project}{qt_finalize_project()}

\section1 Examples

In the following simple case, finalization is handled automatically. If using a
CMake version earlier than 3.19, finalization will be performed immediately as
part of the call. When using CMake 3.19 or later, finalization will occur at the
end of the current directory scope.

\snippet cmake-macros/examples.cmake qt_add_executable_simple

The following example shows a scenario where finalization must be deferred.
The \c OUTPUT_NAME target property affects deployment settings on Android, but
those settings are written out as part of finalizing the target. In order to
support using CMake versions earlier than 3.19, we take over responsibility
for finalizing the target by adding the \c{MANUAL_FINALIZATION} keyword.

\snippet cmake-macros/examples.cmake qt_add_executable_deferred

\include cmake-android-qt-finalize-project-warning.cmake
*/