Creates and finalizes an application target of a platform-specific type.
The command is defined in the
Core component of the
Qt6 package, which can be loaded like so:
find_package(Qt6 REQUIRED COMPONENTS Core)
This command was introduced in Qt 6.0.
qt_add_executable(target [WIN32] [MACOSX_BUNDLE] [MANUAL_FINALIZATION] sources...)
If versionless commands are disabled, use
qt6_add_executable() instead. It supports the same set of arguments as this command.
This command performs the following tasks:
- Create a CMake target of the appropriate type for the target platform.
- Link the target to the
- Handle finalization of the CMake target.
On all platforms except Android, an executable target will be created. All arguments will be passed through to the standard CMake
add_executable() command, except
MANUAL_FINALIZATION (if present). On Android, a
MODULE library will be created and any
MACOSX_BUNDLE options will be ignored. Some target properties will also be set for Android:
SUFFIXtarget property will be set to give the library file name an architecture-specific suffix.
<lang>_VISIBILITY_PRESETtarget properties will be set to
defaultto ensure that the
main()function is visible in the resultant binary.
Since all Qt applications need to link to the
Qt::Core library, this is done for you as a convenience.
After a target is created, further processing or 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 qt_finalize_target() command. You might need to also call the 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
MANUAL_FINALIZATION keyword can be given to indicate that you will explicitly call qt_finalize_target() yourself instead at some later time. In general,
MANUAL_FINALIZATION should not be needed unless the project has to support CMake 3.18 or earlier.
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.
The following example shows a scenario where finalization must be deferred. The
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
qt_add_executable(complexapp MANUAL_FINALIZATION complex.cpp) set_target_properties(complexapp PROPERTIES OUTPUT_NAME Complexify) qt_finalize_target(complexapp)
Warning: If your Android project is built using a CMake version lower than 3.19, make sure that you call qt6_finalize_project() at the end of a top-level CMakeLists.txt.
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.