From de3d4e23ea15dfbb8f81da4003b0bbacd0adc8d0 Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Tue, 21 Nov 2023 15:58:39 +0100 Subject: [PATCH] Add the support for target-based android-build directories When building using CMake it's possible that single CMakeLists.txt may contain multiple android executables. In this case android-build directory mixes the build artifacts from multiple targets. This patch allows using per-target android-build directories in case if Qt support this. The QT_INTERNAL_ANDROID_TARGET_BUILD_DIR_SUPPORT cache variable indicates that Qt has builtin support of this feature and the QT_USE_TARGET_ANDROID_BUILD_DIR cache variable should be set to TRUE by user to enable the functionality project-wide. Task-number: QTBUG-117443 Change-Id: Ic8f576e528ee918a3ebf075a25fa2a414ef85736 Reviewed-by: Reviewed-by: Christian Kandeler Reviewed-by: Alexandru Croitor --- src/plugins/android/androidconstants.h | 3 +++ src/plugins/android/androidmanager.cpp | 8 +++++++- .../cmakeprojectmanager/cmakebuildsystem.cpp | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/plugins/android/androidconstants.h b/src/plugins/android/androidconstants.h index 842e105cf52..e2b15e6358d 100644 --- a/src/plugins/android/androidconstants.h +++ b/src/plugins/android/androidconstants.h @@ -57,6 +57,9 @@ const char AndroidTargets[] = "AndroidTargets"; // QStringList const char AndroidApplicationArgs[] = "AndroidApplicationArgs"; // QString const char AndroidClassPaths[] = "AndroidClassPath"; // QStringList +const char AndroidBuildTargetDirSupport[] = "AndroidBuildTargetDirSupport"; // bool +const char UseAndroidBuildTargetDir[] = "UseAndroidBuildTargetDir"; // bool + // For qbs support const char AndroidApk[] = "Android.APK"; // QStringList const char AndroidManifest[] = "Android.Manifest"; // QStringList diff --git a/src/plugins/android/androidmanager.cpp b/src/plugins/android/androidmanager.cpp index cf665d2d15e..333bb8d147a 100644 --- a/src/plugins/android/androidmanager.cpp +++ b/src/plugins/android/androidmanager.cpp @@ -221,7 +221,13 @@ bool isQtCreatorGenerated(const FilePath &deploymentFile) FilePath androidBuildDirectory(const Target *target) { - return buildDirectory(target) / Constants::ANDROID_BUILD_DIRECTORY; + QString suffix; + const Project *project = target->project(); + if (project->extraData(Android::Constants::AndroidBuildTargetDirSupport).toBool() + && project->extraData(Android::Constants::UseAndroidBuildTargetDir).toBool()) + suffix = QString("-%1").arg(target->activeBuildKey()); + + return buildDirectory(target) / (Constants::ANDROID_BUILD_DIRECTORY + suffix); } FilePath androidAppProcessDir(const Target *target) diff --git a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp index 9a82a8f2956..b524e0b04af 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp @@ -1183,6 +1183,21 @@ void CMakeBuildSystem::updateCMakeConfiguration(QString &errorMessage) cmakeConfig.append(ci); } } + + const bool hasAndroidTargetBuildDirSupport + = CMakeConfigItem::toBool( + cmakeConfig.stringValueOf("QT_INTERNAL_ANDROID_TARGET_BUILD_DIR_SUPPORT")) + .value_or(false); + + const bool useAndroidTargetBuildDir + = CMakeConfigItem::toBool(cmakeConfig.stringValueOf("QT_USE_TARGET_ANDROID_BUILD_DIR")) + .value_or(false); + + project()->setExtraData(Android::Constants::AndroidBuildTargetDirSupport, + QVariant::fromValue(hasAndroidTargetBuildDirSupport)); + project()->setExtraData(Android::Constants::UseAndroidBuildTargetDir, + QVariant::fromValue(useAndroidTargetBuildDir)); + setConfigurationFromCMake(cmakeConfig); }