From 2eff82ea39975b43f511131649e3b7dccedf548b Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Mon, 3 Mar 2025 13:00:48 +0100 Subject: [PATCH] Move the Android deployment config type detecting to a separate function Since the deployment config type detecting is generic, move it a separate function. Pick-to: 6.8 Change-Id: If925b6e14ba0d64a003e7f9ae2a5d701b7886920 Reviewed-by: Alexandru Croitor (cherry picked from commit f10f609db9488629a1abf8c363f32dbd3abdf456) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/Qt6AndroidMacros.cmake | 56 ++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/src/corelib/Qt6AndroidMacros.cmake b/src/corelib/Qt6AndroidMacros.cmake index c8d50d2b0a1..1c06cd917d5 100644 --- a/src/corelib/Qt6AndroidMacros.cmake +++ b/src/corelib/Qt6AndroidMacros.cmake @@ -587,25 +587,8 @@ function(qt6_android_add_apk_target target) list(APPEND extra_args "--verbose") endif() - if(QT_ANDROID_DEPLOY_RELEASE) - message(WARNING "QT_ANDROID_DEPLOY_RELEASE is not a valid Qt variable." - " Please set QT_ANDROID_DEPLOYMENT_TYPE to RELEASE instead.") - endif() - # Setting QT_ANDROID_DEPLOYMENT_TYPE to a value other than Release disables - # release package signing regardless of the build type. - if(QT_ANDROID_DEPLOYMENT_TYPE) - string(TOUPPER "${QT_ANDROID_DEPLOYMENT_TYPE}" deployment_type_upper) - if("${deployment_type_upper}" STREQUAL "RELEASE") - list(APPEND extra_args "--release") - endif() - elseif(NOT QT_BUILD_TESTS) - # Workaround for tests: do not set automatically --release flag if QT_BUILD_TESTS is set. - # Release package need to be signed. Signing is currently not supported by CI. - # What is more, also androidtestrunner is not working on release APKs, - # For example running "adb shell run-as" on release APK will finish with the error: - # run-as: Package '[PACKAGE-NAME]' is not debuggable - list(APPEND extra_args $<$,$,$>:--release>) - endif() + _qt_internal_android_get_deployment_type_option(android_deployment_type_option "--release" "") + list(APPEND extra_args "${android_deployment_type_option}") _qt_internal_check_depfile_support(has_depfile_support) @@ -1772,5 +1755,40 @@ function(_qt_internal_expose_android_package_source_dir_to_ide target) endif() endfunction() +# Return the one of the deployment flags either release or debug depending on +# the preferred config. The returned "flags" are wrapped into generator +# expression so only usable at the generator stage. +function(_qt_internal_android_get_deployment_type_option out_var release_flag debug_flag) + if(QT_ANDROID_DEPLOY_RELEASE) + message(WARNING "QT_ANDROID_DEPLOY_RELEASE is not a valid Qt variable." + " Please set QT_ANDROID_DEPLOYMENT_TYPE to RELEASE instead.") + endif() + # Setting QT_ANDROID_DEPLOYMENT_TYPE to a value other than Release disables + # release package signing regardless of the build type. + if(QT_ANDROID_DEPLOYMENT_TYPE) + string(TOUPPER "${QT_ANDROID_DEPLOYMENT_TYPE}" deployment_type_upper) + if("${deployment_type_upper}" STREQUAL "RELEASE") + set(${out_var} "${release_flag}" PARENT_SCOPE) + else() + set(${out_var} "${debug_flag}" PARENT_SCOPE) + endif() + elseif(NOT QT_BUILD_TESTS) + # Workaround for tests: do not set automatically --release flag if QT_BUILD_TESTS is set. + # Release package need to be signed. Signing is currently not supported by CI. + # What is more, also androidtestrunner is not working on release APKs, + # For example running "adb shell run-as" on release APK will finish with the error: + # run-as: Package '[PACKAGE-NAME]' is not debuggable + string(JOIN "" ${out_var} + "$,$,$>," + "${release_flag}," + "${debug_flag}" + ">" + ) + set(${out_var} "${${out_var}}" PARENT_SCOPE) + else() + set(${out_var} "${debug_flag}" PARENT_SCOPE) + endif() +endfunction() + set(QT_INTERNAL_ANDROID_TARGET_BUILD_DIR_SUPPORT ON CACHE INTERNAL "Indicates that Qt supports per-target Android build directories")