From 8b8679f73d6cfb513141cc0a9f4925a64ca19455 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 7 Jun 2021 17:14:39 +0200 Subject: CMake: Fix global 'apk' target to actually build all apks This means calling 'ninja apk' in a user project with multiple android applications will build all their respective apks. For user projects, make the 'apk' target part of the global 'ALL' target, so that a regular 'ninja' call implies the 'apk' target. We don't do it currently for Qt builds, because certain test executable apks fail to build. Add a QT_NO_GLOBAL_APK_TARGET_PART_OF_ALL variable to allow removing the global apk target from the 'all' target. Pick-to: 6.1 Task-number: QTBUG-94264 Change-Id: I171b9da50eb7d670176704bd26dc1c492118b434 Reviewed-by: Joerg Bornemann Reviewed-by: Qt CI Bot --- src/corelib/Qt6AndroidMacros.cmake | 40 +++++++++++++++++++++++--------- src/corelib/Qt6CoreConfigExtras.cmake.in | 1 + 2 files changed, 30 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/corelib/Qt6AndroidMacros.cmake b/src/corelib/Qt6AndroidMacros.cmake index cf22166e7b..80baaed68e 100644 --- a/src/corelib/Qt6AndroidMacros.cmake +++ b/src/corelib/Qt6AndroidMacros.cmake @@ -281,17 +281,9 @@ function(qt6_android_add_apk_target target) message(FATAL_ERROR "Target ${target} is not a valid android executable target\n") endif() - # Create a top-level "apk" target for convenience, so that users can call 'ninja apk'. - # It will trigger building all the target specific apk build targets that are added via this - # function. - # Allow opt-out. - if(NOT QT_NO_GLOBAL_APK_TARGET) - if(NOT TARGET apk) - add_custom_target(apk - DEPENDS ${target}_make_apk - COMMENT "Building all apks" - ) - endif() + # Make global apk target depend on the current apk target. + if(TARGET apk) + add_dependencies(apk ${target}_make_apk) endif() set(deployment_tool "${QT_HOST_PATH}/${QT6_HOST_INFO_BINDIR}/androiddeployqt") @@ -332,6 +324,32 @@ function(qt6_android_add_apk_target target) DEPENDS "${apk_intermediate_file_path}") endfunction() +function(_qt_internal_create_global_apk_target) + # Create a top-level "apk" target for convenience, so that users can call 'ninja apk'. + # It will trigger building all the apk build targets that are added as part of the project. + # Allow opting out. + if(NOT QT_NO_GLOBAL_APK_TARGET) + if(NOT TARGET apk) + # Some Qt tests helper executables have their apk build process failing. + # Don't build apks by default when doing a Qt build. + set(skip_add_to_all FALSE) + if(QT_BUILDING_QT) + set(skip_add_to_all TRUE) + endif() + + option(QT_NO_GLOBAL_APK_TARGET_PART_OF_ALL + "Skip building apks as part of the default 'ALL' target" ${skip_add_to_all}) + + set(part_of_all "ALL") + if(QT_NO_GLOBAL_APK_TARGET_PART_OF_ALL) + set(part_of_all "") + endif() + + add_custom_target(apk ${part_of_all} COMMENT "Building all apks") + endif() + endif() +endfunction() + if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS) function(qt_android_add_apk_target) qt6_android_add_apk_target(${ARGV}) diff --git a/src/corelib/Qt6CoreConfigExtras.cmake.in b/src/corelib/Qt6CoreConfigExtras.cmake.in index 25b3f5acd5..f86d4ad5bf 100644 --- a/src/corelib/Qt6CoreConfigExtras.cmake.in +++ b/src/corelib/Qt6CoreConfigExtras.cmake.in @@ -46,6 +46,7 @@ set(_Qt6CTestMacros "${_Qt6CoreConfigDir}/Qt6CTestMacros.cmake") if(ANDROID_PLATFORM) include("${CMAKE_CURRENT_LIST_DIR}/@QT_CMAKE_EXPORT_NAMESPACE@AndroidMacros.cmake") + _qt_internal_create_global_apk_target() endif() if(EMSCRIPTEN) -- cgit v1.2.3