diff options
author | Craig Scott <craig.scott@qt.io> | 2020-12-17 12:30:43 +1100 |
---|---|---|
committer | Craig Scott <craig.scott@qt.io> | 2021-01-11 16:58:28 +1100 |
commit | 0be2ecee37ee76f04ff73f782014108c15a5831f (patch) | |
tree | e9632bcbd9086c0a149dc4287dd93c83ab325f33 /src/corelib | |
parent | c34c6af3740052617ee9f0876e2720046f0e6bb7 (diff) |
Doc: Add partial documentation for CMake API (tech preview)
There are still other parts of the CMake API that are not yet
documented. This change only addresses qt_add_executable() and the
Android-related commands it uses.
Fixes: QTBUG-88839
Task-number: QTBUG-84482
Pick-to: 6.0
Change-Id: I761b5ce908d1f62284baabe2d414cd37a0efe83d
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/doc/snippets/cmake-macros/examples.cmake | 15 | ||||
-rw-r--r-- | src/corelib/doc/src/cmake-macros.qdoc | 283 | ||||
-rw-r--r-- | src/corelib/doc/src/cmake-properties.qdoc | 204 | ||||
-rw-r--r-- | src/corelib/doc/src/cmake-variables.qdoc | 100 |
4 files changed, 601 insertions, 1 deletions
diff --git a/src/corelib/doc/snippets/cmake-macros/examples.cmake b/src/corelib/doc/snippets/cmake-macros/examples.cmake index 820b28cf88..685b29db01 100644 --- a/src/corelib/doc/snippets/cmake-macros/examples.cmake +++ b/src/corelib/doc/snippets/cmake-macros/examples.cmake @@ -73,3 +73,18 @@ qt_import_plugins(myapp EXCLUDE_BY_TYPE sqldrivers ) #! [qt_import_plugins] + +#! [qt_add_executable_simple] +qt_add_executable(simpleapp main.cpp) +#! [qt_add_executable_simple] + +#! [qt_add_executable_deferred] +qt_add_executable(complexapp MANUAL_FINALIZATION complex.cpp) +set_target_properties(complexapp PROPERTIES OUTPUT_NAME Complexify) +qt_finalize_target(complexapp) +#! [qt_add_executable_deferred] + +#! [qt_android_deploy_basic] +qt_android_generate_deployment_settings(myapp) +qt_android_add_apk_target(myapp) +#! [qt_android_deploy_basic] diff --git a/src/corelib/doc/src/cmake-macros.qdoc b/src/corelib/doc/src/cmake-macros.qdoc index a86913fed9..af3ab324b9 100644 --- a/src/corelib/doc/src/cmake-macros.qdoc +++ b/src/corelib/doc/src/cmake-macros.qdoc @@ -241,7 +241,7 @@ when scanning the source files with \c{moc}. \title qt_import_plugins \target qt6_import_plugins -\brief Specifies a custom set of plugins to import for a static Qt build +\brief Specifies a custom set of plugins to import for a static Qt build. \section1 Synopsis @@ -304,3 +304,284 @@ In the snippet above, the following occurs with the executable \c myapp: \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. 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. 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_PACKAGE_SOURCE_DIR}{QT_ANDROID_PACKAGE_SOURCE_DIR} +\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} +\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. +*/ diff --git a/src/corelib/doc/src/cmake-properties.qdoc b/src/corelib/doc/src/cmake-properties.qdoc new file mode 100644 index 0000000000..0a24fcba78 --- /dev/null +++ b/src/corelib/doc/src/cmake-properties.qdoc @@ -0,0 +1,204 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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 cmake-target-property-QT_ANDROID_DEPLOYMENT_DEPENDENCIES.html +\ingroup cmake-properties-qtcore +\ingroup cmake-target-properties-qtcore + +\title QT_ANDROID_DEPLOYMENT_DEPENDENCIES +\target cmake-target-property-QT_ANDROID_DEPLOYMENT_DEPENDENCIES + +\brief Overrides the Qt dependencies added to the target's deployment. + +\preliminarycmakeproperty +\cmakepropertyandroidonly + +By default, \l androiddeployqt will detect the dependencies of your +application. However, since run-time usage of plugins cannot be detected, +there could be false positives, as your application might depend on any +plugin that is a potential dependency. If you want to minimize the size of +your \c APK, it's possible to override the automatic detection using this +property. This should contain a list of all Qt files which need to be +included, with paths relative to the Qt install root. + +\note Only the Qt files specified with this variable are included. Failing +to include all the correct files can result in crashes. It's also important +to make sure the files are listed in the correct loading order. This variable +provides a way to override the automatic detection entirely, so if a library +is listed before its dependencies, it will fail to load on some devices. + +\sa{qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()} +*/ + +/*! +\page cmake-target-property-QT_ANDROID_EXTRA_LIBS.html +\ingroup cmake-properties-qtcore +\ingroup cmake-target-properties-qtcore + +\title QT_ANDROID_EXTRA_LIBS +\target cmake-target-property-QT_ANDROID_EXTRA_LIBS + +\brief Extra libraries to deploy with the target. + +\preliminarycmakeproperty +\cmakepropertyandroidonly + +A list of external libraries that will be copied into your application's +\c libs folder and loaded on start-up. This can be used, for instance, +to enable OpenSSL in your application. For more information, see +\l{Adding OpenSSL Support for Android}. + +\sa{qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()} +*/ + +/*! +\page cmake-target-property-QT_ANDROID_EXTRA_PLUGINS.html +\ingroup cmake-properties-qtcore +\ingroup cmake-target-properties-qtcore + +\title QT_ANDROID_EXTRA_PLUGINS +\target cmake-target-property-QT_ANDROID_EXTRA_PLUGINS + +\brief Extra Qt plugins to deploy with the target. + +\preliminarycmakeproperty +\cmakepropertyandroidonly + +Specifies a path to C++ plugins or resources that your application has to bundle +but that cannot be delivered through the assets system, such as QML plugins. +With this variable, \l androiddeployqt will make sure everything is packaged +and deployed properly. + +\c QT_ANDROID_EXTRA_PLUGINS must point to the directory where the extra plugin(s) +are built. In addition, the build directory structure must follow a naming +convention similar to Qt plugins, that is, \e {plugins/<plugin name>}. +\c QT_ANDROID_EXTRA_PLUGINS should point to the \e {plugins} part of that path. + +The plugins libraries should have the name format +\e {libplugins_<type>_<name>_<abi>.so}. This will ensure that the correct name +mangling is applied to the plugin library. +\omit +TODO: Not yet documented, API still under review - see QTBUG-88763 +See the \l{qt6_add_plugin}{qt_add_plugin()} command for the easiest way to achieve +that. +\endomit + +\sa{qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()} +*/ + +/*! +\page cmake-target-property-QT_ANDROID_PACKAGE_SOURCE_DIR.html +\ingroup cmake-properties-qtcore +\ingroup cmake-target-properties-qtcore + +\title QT_ANDROID_PACKAGE_SOURCE_DIR +\target cmake-target-property-QT_ANDROID_PACKAGE_SOURCE_DIR + +\brief Path to a custom Android package template. + +\preliminarycmakeproperty +\cmakepropertyandroidonly + +Specifies the path for a custom Android package template. The Android package +template contains: +\list + \li AndroidManifest.xml file + \li build.gradle file and other Gradle scripts + \li res/values/libs.xml file +\endlist + +The path specified by this variable can contain custom Java classes under +\c src directory. By default, the \l androiddeployqt tool copies the +application template from the Qt for Android installation path into your +project's build directory, then it copies the contents of the path specified +by this variable on top of that, overwriting any existing files. For +instance, you can make a custom \c {AndroidManifest.xml} for your application, +then place this directly into the directory specified by this variable. + +\sa{qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()} +*/ + +/*! +\page cmake-target-property-QT_QML_ROOT_PATH.html +\ingroup cmake-properties-qtcore +\ingroup cmake-target-properties-qtcore + +\title QT_QML_ROOT_PATH +\target cmake-target-property-QT_QML_ROOT_PATH + +\brief Overrides the location of the application's qml directory. + +\preliminarycmakeproperty + +This property is currently only used when generating a deployment settings file +for Android. If the property is set, it specifies the path to the application's +\c{qml} directory. If it is not set, the \c{SOURCE_DIR} property of the target +will be used instead. + +\sa{qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()} +*/ + +/*! +\page cmake-target-property-QT_QML_IMPORT_PATH.html +\ingroup cmake-properties-qtcore +\ingroup cmake-target-properties-qtcore + +\title QT_QML_IMPORT_PATH +\target cmake-target-property-QT_QML_IMPORT_PATH + +\brief Specifies a list of directories to search for QML imports. + +\preliminarycmakeproperty + +This property is currently only used when generating a deployment settings file +for Android. It typically contains just the path to Qt's \c{qml} directory, but +it can be a list that contains other locations to be searched as well. +For application-specific QML imports, use +\l{cmake-target-property-QT_QML_ROOT_PATH}{QT_QML_ROOT_PATH} instead. + +\sa{qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()} +*/ + +/*! +\page cmake-target-property-QT_ANDROID_DEPLOYMENT_SETTINGS_FILE.html +\ingroup cmake-properties-qtcore +\ingroup cmake-target-properties-qtcore + +\title QT_ANDROID_DEPLOYMENT_SETTINGS_FILE +\target cmake-target-property-QT_ANDROID_DEPLOYMENT_SETTINGS_FILE + +\brief Specifies the location of a target's generated deployment settings file. + +\preliminarycmakeproperty +\cmakepropertyandroidonly + +This property will be set by +\l{qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()}. +Projects should not try to set this property themselves, as it will be ignored +and overwritten by that command. +*/ diff --git a/src/corelib/doc/src/cmake-variables.qdoc b/src/corelib/doc/src/cmake-variables.qdoc new file mode 100644 index 0000000000..d3f73ab918 --- /dev/null +++ b/src/corelib/doc/src/cmake-variables.qdoc @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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 cmake-variable-ANDROID_NDK_HOST_SYSTEM_NAME.html +\ingroup cmake-variables +\ingroup cmake-variables-qtcore + +\title ANDROID_NDK_HOST_SYSTEM_NAME +\target cmake-variable-ANDROID_NDK_HOST_SYSTEM_NAME + +\brief Android-specific architecture of the host system. + +\preliminarycmakevariable +\cmakevariableandroidonly + +This is normally set by the Android NDK toolchain file. It is written out as +part of the deployment settings for a target. + +\sa{qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()} +*/ + +/*! +\page cmake-variable-ANDROID_SDK_ROOT.html +\ingroup cmake-variables +\ingroup cmake-variables-qtcore + +\title ANDROID_SDK_ROOT +\target cmake-variable-ANDROID_SDK_ROOT + +\brief Location of the Android SDK. + +\preliminarycmakevariable +\cmakevariableandroidonly + +This specifies the location of the Android SDK when building for the Android platform. +It is written out as part of the deployment settings for a target. + +\sa{qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()}. +*/ + +/*! +\page cmake-variable-QT_ANDROID_APPLICATION_ARGUMENTS.html +\ingroup cmake-variables +\ingroup cmake-variables-qtcore + +\title QT_ANDROID_APPLICATION_ARGUMENTS +\target cmake-variable-QT_ANDROID_APPLICATION_ARGUMENTS + +\brief List of arguments to pass to Android applications. + +\preliminarycmakevariable +\cmakevariableandroidonly + +This contains a list of arguments to be passed to Android applications. It is written +out as part of the deployment settings for a target. + +\sa{qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()} +*/ + +/*! +\page cmake-variable-QT_HOST_PATH.html +\ingroup cmake-variables +\ingroup cmake-variables-qtcore + +\title QT_HOST_PATH +\target cmake-variable-QT_HOST_PATH + +\brief Location of the host Qt installation when cross-compiling. + +\preliminarycmakevariable + +When cross-compiling, this must be set to the install location of Qt for the host +platform. It is used to locate tools to be run on the host (\l{moc}, \l{rcc}, +\l{androiddeployqt}, and so on). +*/ |