From 6abaff810a41e6e4490a47ff4ea8d50308bdba3b Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Thu, 18 Aug 2022 16:54:30 +0200 Subject: CMake: Collect IMPORTED library dependencies for android deployment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously _qt_internal_collect_apk_dependencies() only collected targets that were built by the current project and informed androiddeployqt their directory paths for deployment consideration. The libraries would be bundled into the apk based on whether the application links to any of those libraries directly, e.g. via target_link_libraries. CMake 3.21 added a new feature that allows us to query all IMPORTED targets in a directory scope. Using this information we can now tell androiddeployqt about these libraries as well, of course only when a new enough CMake version is used. Introduce _qt_internal_collect_apk_imported_dependencies_defer to do that. In contrast to _qt_internal_collect_apk_dependencies(), the IMPORTED libraries are collected by recursively looking at a target's directory scope and its parent directories, rather than child subdirectories. Also, the collection / deferral is done when the target's directory scope has finished processing, rather than when the root project has finished processing. Why? IMPORTED libraries are usually non-global, which means we can't refer to them in parent scopes using functions like get_target_property, the targets don't exist in those scopes. Note that the code only covers IMPORTED target libraries. It does not cover INTERFACE libraries, plain library names or file paths specified in target_link_libraries. It also doesn't account for loadable libraries (dlopen()ed ones). In such cases, projects still need to manually specify the library paths in the executable's QT_ANDROID_EXTRA_LIBS target property. To prevent the deployment json file from being extra long when looking for IMPORTED libraries, filter out paths to Qt modules or plugins by checking for the _qt_package_version property. These are handled via a different code path in anddroiddeployqt, so there's no reason to duplicate the information. Added documentation for how to opt out of this new behavior. Amends d20f4ae706559fb7de8db9dd4845f7ce3936061a [ChangeLog][CMake][Android] Imported targets are now considered during Android deployment when using CMake 3.21+. Fixes: QTBUG-94714 Fixes: QTBUG-105165 Change-Id: I9f01cdc4e63004e4768027e412899e441e72bf04 Reviewed-by: Jörg Bornemann Reviewed-by: Paul Wicking Reviewed-by: Assam Boudjelthia --- .../doc/src/cmake/cmake-configure-variables.qdoc | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/corelib/doc/src/cmake/cmake-configure-variables.qdoc') diff --git a/src/corelib/doc/src/cmake/cmake-configure-variables.qdoc b/src/corelib/doc/src/cmake/cmake-configure-variables.qdoc index 4b759c649b..bef29a6a94 100644 --- a/src/corelib/doc/src/cmake/cmake-configure-variables.qdoc +++ b/src/corelib/doc/src/cmake/cmake-configure-variables.qdoc @@ -225,6 +225,33 @@ resolving dependencies between libraries. Set \c QT_NO_COLLECT_BUILD_TREE_APK_DEPS to \c TRUE to disable this behavior. \sa {qt6_finalize_project}{qt_finalize_project()} +\sa {cmake-variable-QT_NO_COLLECT_IMPORTED_TARGET_APK_DEPS}{QT_NO_COLLECT_IMPORTED_TARGET_APK_DEPS} +*/ + +/*! +\page cmake-variable-QT_NO_COLLECT_IMPORTED_TARGET_APK_DEPS.html +\ingroup cmake-variables-qtcore + +\title QT_NO_COLLECT_IMPORTED_TARGET_APK_DEPS +\target cmake-variable-QT_NO_COLLECT_IMPORTED_TARGET_APK_DEPS + +\summary {Prevents collecting of imported targets during Android deployment.} + +\cmakevariablesince 6.5 +\preliminarycmakevariable +\cmakevariableandroidonly + +When using CMake version 3.21 or later, the build system collects the locations of +imported shared library targets that might be relevant for deployment. +The collected targets are those that are reachable from the the directory scope +of the currently processed executable target. That includes the target's source directory +scope and its parents. +The collected locations are passed to \l androiddeployqt for deployment consideration when +resolving dependencies between libraries. +Set \c QT_NO_COLLECT_IMPORTED_TARGET_APK_DEPS to \c TRUE to disable this behavior. + +\sa {qt6_finalize_project}{qt_finalize_project()} +\sa {cmake-variable-QT_NO_COLLECT_BUILD_TREE_APK_DEPS}{QT_NO_COLLECT_BUILD_TREE_APK_DEPS} */ /*! -- cgit v1.2.3