/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
\page qt_wrap_cpp.html
\ingroup cmake-macros-qtcore

\title qt_wrap_cpp
\target qt6_wrap_cpp

\brief Creates \c{.moc} files from sources.

\section1 Synopsis

\badcode
qt_wrap_cpp(<VAR> src_file1 [src_file2 ...]
            [TARGET target]
            [OPTIONS ...]
            [DEPENDS ...])

qt6_wrap_cpp(<VAR> src_file1 [src_file2 ...]
             [TARGET target]
             [OPTIONS ...]
             [DEPENDS ...])
\endcode

\section1 Description

Creates rules for calling the \l{moc}{Meta-Object Compiler (moc)} on the given
source files. For each input file, an output file is generated in the build
directory. The paths of the generated files are added to \c{<VAR>}.

\note This is a low-level macro. See the \l{CMake AUTOMOC Documentation} for a
more convenient way to let source files be processed with \c{moc}.

\section1 Arguments

You can set an explicit \c{TARGET}. This will make sure that the target
properties \c{INCLUDE_DIRECTORIES} and \c{COMPILE_DEFINITIONS} are also used
when scanning the source files with \c{moc}.

You can set additional \c{OPTIONS} that should be added to the \c{moc} calls.
You can find possible options in the \l{moc}{moc documentation}.

\c{DEPENDS} allows you to add additional dependencies for recreation of the
generated files. This is useful when the sources have implicit dependencies,
like code for a Qt plugin that includes a \c{.json} file using the
Q_PLUGIN_METADATA() macro.

\section1 Examples

\snippet cmake-macros/examples.cmake qt_wrap_cpp
*/

/*!
\page qt_add_resources.html
\ingroup cmake-macros-qtcore

\title qt_add_resources
\target qt6_add_resources

\brief Compiles binary resources into source code.

\section1 Synopsis

\badcode
qt_add_resources(<VAR> file1.qrc [file2.qrc ...]
                  [OPTIONS ...])

qt6_add_resources(<VAR> file1.qrc [file2.qrc ...]
                  [OPTIONS ...])
\endcode

Since 6.0:

\badcode
qt_add_resources(<TARGET> <RESOURCE_NAME>
                  [PREFIX <PATH>]
                  [LANG <LANGUAGE>]
                  [BASE <PATH>]
                  [FILES ...] [OPTIONS ...])

qt6_add_resources(<TARGET> <RESOURCE_NAME>
                  [PREFIX <PATH>]
                  [LANG <LANGUAGE>]
                  [BASE <PATH>]
                  [FILES ...] [OPTIONS ...])
\endcode

\section1 Description

To add resources, you can pass either a variable name or a target as the first
argument of the command.

When passing a variable name as first argument, \c qt_add_resources creates
source code from Qt resource files using the \l{Resource Compiler (rcc)}. Paths
to the generated source files are added to \c{<VAR>}.

When passing a target as first argument, the function creates a resource with
the name \c{RESOURCE_NAME}, containing the specified \c{FILES}. The resource is
automatically linked into \c{TARGET}.

For embedding bigger resources, see \l qt_add_big_resources.

See \l{The Qt Resource System} for a general description of Qt resources.

\section1 Arguments of the target-based variant

\c PREFIX specifies a path prefix under which all files of this resource are
accessible from C++ code. This corresponds to the XML attribute \c prefix of the
\c .qrc file format. If \c PREFIX is not given, the target property
\l{cmake-target-property-QT_RESOURCE_PREFIX}{QT_RESOURCE_PREFIX} is used.

\c LANG specifies the locale of this resource. This corresponds to the XML
attribute \c lang of the \c .qrc file format.

\c BASE is a path prefix that denotes the root point of the file's alias. For
example, if \c BASE is \c{"assets"} and \c FILES is
\c{"assets/images/logo.png"}, then the alias of that file is
\c{"images/logo.png"}.

Alias settings for files need to be set via the \c QT_RESOURCE_ALIAS source file
property.

\section1 Arguments of both variants

You can set additional \c{OPTIONS} that should be added to the \c{rcc} calls.
You can find possible options in the \l{rcc}{rcc documentation}.

\section1 Examples

Variable variant, using a .qrc file:
\snippet cmake-macros/examples.cmake qt_add_resources

Target variant, using immediate resources:
\snippet cmake-macros/examples.cmake qt_add_resources_target

\section1 Caveats

When adding multiple resources, \c{RESOURCE_NAME} must be unique across all
resources linked into the final target.

This especially affects static builds. There, the same resource name in
different static libraries conflict in the consuming target.
*/

/*!
\page qt_add_bigresources.html
\ingroup cmake-macros-qtcore

\title qt_add_big_resources
\target qt6_add_big_resources

\brief Compiles big binary resources into object code.

\section1 Synopsis

\badcode
qt_add_big_resources(<VAR> file1.qrc [file2.qrc ...]
                     [OPTIONS ...])

qt6_add_big_resources(<VAR> file1.qrc [file2.qrc ...]
                     [OPTIONS ...])
\endcode

\section1 Description

Creates compiled object files from Qt resource files using the
\l{Resource Compiler (rcc)}. Paths to the generated files are added to
\c{<VAR>}.

This is similar to \l qt_add_resources, but directly
generates object files (\c .o, \c .obj) files instead of C++ source code.
This allows to embed bigger resources, where compiling to C++ sources and then
to binaries would be too time consuming or memory intensive.

\note This macro is only available if using \c{CMake} 3.9 or later.

\section1 Arguments

You can set additional \c{OPTIONS} that should be added to the \c{rcc} calls.
You can find possible options in the \l{rcc}{rcc documentation}.

\section1 Examples

\snippet cmake-macros/examples.cmake qt_add_big_resources
*/

/*!
\page qt_add_binary_resources.html
\ingroup cmake-macros-qtcore

\title qt_add_binary_resources
\target qt6_add_binary_resources

\brief Creates an \c{RCC} file from a list of Qt resource files.

\section1 Synopsis

\badcode
qt_add_binary_resources(target file1.qrc [file2.qrc ...]
                        [DESTINATION ...]
                        [OPTIONS ...])

qt6_add_binary_resources(target file1.qrc [file2.qrc ...]
                        [DESTINATION ...]
                        [OPTIONS ...])
\endcode

\section1 Description

Adds a custom \c target that compiles Qt resource files into a binary \c{.rcc}
file.

\section1 Arguments

\c{DESTINATION} sets the path of the generated \c{.rcc} file. The default is
\c{${CMAKE_CURRENT_BINARY_DIR}/${target}.rcc}.

You can set additional \c{OPTIONS} that should be added to the \c{rcc} calls.
You can find possible options in the \l{rcc}{rcc documentation}.

\section1 Examples

\snippet cmake-macros/examples.cmake qt_add_binary_resources
*/

/*!
\page qt_generate_moc.html
\ingroup cmake-macros-qtcore

\title qt_generate_moc
\target qt6_generate_moc

\brief Calls moc on an input file.

\section1 Synopsis

\badcode
qt_generate_moc(src_file dest_file
                [TARGET target])

qt6_generate_moc(src_file dest_file
                [TARGET target])
\endcode

\section1 Description

Creates a rule to call the \l{moc}{Meta-Object Compiler (moc)} on \c src_file
and store the output in \c dest_file.

\note This is a low-level macro. See the \l{CMake AUTOMOC Documentation} for a
more convenient way to let source files be processed with \c{moc}.
\l qt_wrap_cpp is also similar, but automatically generates a temporary file
path for you.

\section1 Arguments

You can set an explicit \c{TARGET}. This will make sure that the target
properties \c{INCLUDE_DIRECTORIES} and \c{COMPILE_DEFINITIONS} are also used
when scanning the source files with \c{moc}.

\section1 Examples

\snippet cmake-macros/examples.cmake qt_generate_moc
*/

/*!
\page qt_import_plugins.html
\ingroup cmake-macros-qtcore

\title qt_import_plugins
\target qt6_import_plugins

\brief Specifies a custom set of plugins to import for a static Qt build.

\section1 Synopsis

\badcode
qt_import_plugins(target
                  [INCLUDE plugin ...]
                  [EXCLUDE plugin ...]
                  [INCLUDE_BY_TYPE plugin_type plugin ...]
                  [EXCLUDE_BY_TYPE plugin_type])

qt6_import_plugins(target
                  [INCLUDE plugin ...]
                  [EXCLUDE plugin ...]
                  [INCLUDE_BY_TYPE plugin_type plugin ...]
                  [EXCLUDE_BY_TYPE plugin_type])
\endcode

\section1 Description

Specifies a custom set of plugins to import. The optional arguments:
\c INCLUDE, \c EXCLUDE, \c INCLUDE_BY_TYPE, and \c EXCLUDE_BY_TYPE,
can be used more than once.

\list
\li \c INCLUDE -- can be used to specify a list of plugins to import.
\li \c EXCLUDE -- can be used to specify a list of plugins to exclude.
\li \c INCLUDE_BY_TYPE -- can be used to override the list of plugins to
       import for a certain plugin type.
\li \c EXCLUDE_BY_TYPE -- can be used to specify a plugin type to exclude;
       then no plugins of that type are imported.
\endlist

Qt provides plugin types such as \c imageformats, \c platforms,
and \c sqldrivers.

If the command isn't used the target automatically links against
a sane set of default plugins, for each Qt module that the target is linked
against. For more information, see
\l{CMake target_link_libraries Documentation}{target_link_libraries}.

Each plugin comes with a C++ stub file that automatically
initializes the plugin. Consequently, any target that links against a plugin
has this C++ file added to its \c SOURCES.

\note This command imports plugins from static Qt builds only.
On shared builds, it does nothing.

\section1 Examples

\snippet cmake-macros/examples.cmake qt_import_plugins

In the snippet above, the following occurs with the executable \c myapp:

\list
\li The \c Qt6::QCocoaIntegrationPlugin is imported into myapp.
\li The \c Qt6::QMinimalIntegrationPlugin plugin is
    excluded from being automatically imported into myapp.
\li The default list of plugins for \c imageformats is
    overridden to only include Qt6::QGifPlugin and Qt6::QJpegPlugin.
\li All \c sqldrivers plugins are excluded from automatic importing.
\endlist
*/

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

\title qt_add_executable
\target qt6_add_executable

\brief Creates and finalizes an application target of a platform-specific type.

\preliminarycmakecommand

\section1 Synopsis

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

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

\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_executable}{qt_finalize_executable()} command.

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_executable}{qt_finalize_executable()}
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_executable}{qt_finalize_executable()}

\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
*/

/*!
\page qt_finalize_executable.html
\ingroup cmake-macros-qtcore

\title qt_finalize_executable
\target qt6_finalize_executable

\brief Handles various common platform-specific tasks associated with Qt targets.

\preliminarycmakecommand

\section1 Synopsis

\badcode
qt_finalize_executable(target)

qt6_finalize_executable(target)
\endcode

\section1 Description

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. These steps are expected to be performed within the
same directory scope as the one in which the \c{target} was created, so this
command should also be called from that same directory scope.

This command implements the following, as appropriate for the platform and
target provided:

\list
\li When targeting Android, generate a deployment settings file for the target.
\li Create a build target for generating an APK if building for Android.
\endlist

This command is ordinarily invoked as part of a call to
\l{qt6_add_executable}{qt_add_executable()}. The timing of when that call takes
place and when it might need to be called explicitly by a project is discussed
in the documentation of that command.
*/

/*!
\page qt_android_apply_arch_suffix.html
\ingroup cmake-macros-qtcore

\title qt_android_apply_arch_suffix
\target qt6_android_apply_arch_suffix

\brief Configures the target binary's name to include an architecture-specific suffix.

\preliminarycmakecommand
\cmakecommandandroidonly

\section1 Synopsis

\badcode
qt_android_apply_arch_suffix(target)

qt6_android_apply_arch_suffix(target)
\endcode

\section1 Description

The CMake \c{SUFFIX} target property controls the suffix used on the file name
of the target's built binary. This command is a convenience for setting that
property to an architecture-specific value. This is useful when installing
multiple builds for different Android architectures into the same install
location, as it prevents the libraries for different architectures from
overwriting each other.
*/

/*!
\page qt_android_generate_deployment_settings.html
\ingroup cmake-macros-qtcore

\title qt_android_generate_deployment_settings
\target qt6_android_generate_deployment_settings

\brief Generates the deployment settings file needed by androiddeployqt.

\preliminarycmakecommand
\cmakecommandandroidonly

\section1 Synopsis

\badcode
qt_android_generate_deployment_settings(target)

qt6_android_generate_deployment_settings(target)
\endcode

\section1 Description

The \c{androiddeployqt} tool expects a deployment settings file as input. This
command reads CMake variables and properties of the \c{target} to generate such
a file in the target's binary directory. Upon return, the full path to this file
is available in the target's \c{QT_ANDROID_DEPLOYMENT_SETTINGS_FILE} property.

\section2 CMake Variables

A number of variables are used while generating the deployment settings file.
Some are provided by Qt, others by CMake or the Android NDK.

\list
\li \l{cmake-variable-ANDROID_NDK_HOST_SYSTEM_NAME}{ANDROID_NDK_HOST_SYSTEM_NAME}
\li \l{cmake-variable-ANDROID_SDK_ROOT}{ANDROID_SDK_ROOT}
\li \c{CMAKE_ANDROID_ARCH_ABI}
\li \c{CMAKE_ANDROID_NDK}
\li \c{CMAKE_SYSROOT}
\li \l{cmake-variable-QT_ANDROID_APPLICATION_ARGUMENTS}{QT_ANDROID_APPLICATION_ARGUMENTS}
\li \l{cmake-variable-QT_HOST_PATH}{QT_HOST_PATH}
\endlist

\section2 Target Properties

The properties below will be read from the specified \c{target}. Note that this
command is called as part of target finalization (see
\l{qt6_finalize_executable}{qt_finalize_executable()}). If you are using
\l{qt6_add_executable}{qt_add_executable()} to create the target and you need to
modify some of these target properties, you need to ensure that target
finalization is deferred. See \l{qt6_add_executable}{qt_add_executable()} for
how to accomplish this.

\list
\li \l{cmake-target-property-QT_ANDROID_DEPLOYMENT_DEPENDENCIES}{QT_ANDROID_DEPLOYMENT_DEPENDENCIES}
\li \l{cmake-target-property-QT_ANDROID_EXTRA_LIBS}{QT_ANDROID_EXTRA_LIBS}
\li \l{cmake-target-property-QT_ANDROID_EXTRA_PLUGINS}{QT_ANDROID_EXTRA_PLUGINS}
\li \l{cmake-target-property-QT_ANDROID_MIN_SDK_VERSION}{QT_ANDROID_MIN_SDK_VERSION}
\li \l{cmake-target-property-QT_ANDROID_PACKAGE_SOURCE_DIR}{QT_ANDROID_PACKAGE_SOURCE_DIR}
\li \l{cmake-target-property-QT_ANDROID_TARGET_SDK_VERSION}{QT_ANDROID_TARGET_SDK_VERSION}
\li \l{cmake-target-property-QT_ANDROID_VERSION_NAME}{QT_ANDROID_VERSION_NAME}
\li \l{cmake-target-property-QT_ANDROID_VERSION_CODE}{QT_ANDROID_VERSION_CODE}
\li \l{cmake-target-property-QT_QML_IMPORT_PATH}{QT_QML_IMPORT_PATH}
\li \l{cmake-target-property-QT_QML_ROOT_PATH}{QT_QML_ROOT_PATH}
\li \l{cmake-target-property-qt_no_entrypoint}{qt_no_entrypoint}
\endlist

Upon return, the \c{QT_ANDROID_DEPLOYMENT_SETTINGS_FILE} target property will
contain the location of the generated deployment settings file.

\sa {qt6_android_add_apk_target}{qt_android_add_apk_target()},
    {qt6_finalize_executable}{qt_finalize_executable()}

\section1 Example

\snippet cmake-macros/examples.cmake qt_android_deploy_basic
*/

/*!
\page qt_android_add_apk_target.html
\ingroup cmake-macros-qtcore

\title qt_android_add_apk_target
\target qt6_android_add_apk_target

\brief Defines a build target that runs androiddeployqt to produce an APK.

\preliminarycmakecommand
\cmakecommandandroidonly

\section1 Synopsis

\badcode
qt_android_add_apk_target(target)

qt6_android_add_apk_target(target)
\endcode

\section1 Description

The \c{<target>_make_apk} custom target created by this command takes an Android
deployment settings file and generates an APK by running \c{androiddeployqt}.
The location of the settings file is taken from the \c{target}'s
\c{QT_ANDROID_DEPLOYMENT_SETTINGS_FILE} property. This file is typically created by
\l{qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()}.
The \c{.apk} file will be generated in an \c{android-build} subdirectory below
the CMake build directory of the \c{target}.

The \c{<target>_make_apk} target will be automatically added as a dependency of
the \c{apk} build target, which will be created if it doesn't already exist.
This can be disabled by setting the \c{QT_NO_GLOBAL_APK_TARGET} variable to true.

\sa {qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()},
    {qt6_finalize_executable}{qt_finalize_executable()}

\section1 Example

\snippet cmake-macros/examples.cmake qt_android_deploy_basic

The above commands define the build targets \c{myapp_make_apk} and \c{apk},
which can be used to generate just the \c{myapp} APK or all APKs in the project
respectively.
*/
