From 91e53a7b9cb30e330c86c8bc460159fe14945042 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= <tor.arne.vestbo@digia.com>
Date: Thu, 6 Nov 2014 16:11:01 +0100
Subject: [PATCH] Xcode: Make sure QMAKE_PRE_LINK dependencies are complete for
 multi-arch builds

With multi-architecture builds and ONLY_ACTIVE_ARCH set to NO, Xcode will
build the final target for multiple architectures at the same time, but
CURRENT_ARCH will only match one of them, so we failed to set up the
right dependencies for our pre-link step, causing the step to happen
after linking in some cases.

We now build an exhaustive dependency list based on QMAKE_XCODE_ARCHS,
so that ONLY_ACTIVE_ARCH=NO can be used for release builds targeted at
the App Store.

Change-Id: I6702f020a6970807adc624779f6dde09be62beb9
Reviewed-by: Andy Shaw <andy.shaw@digia.com>
---
 qmake/generators/mac/pbuilder_pbx.cpp | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/qmake/generators/mac/pbuilder_pbx.cpp b/qmake/generators/mac/pbuilder_pbx.cpp
index 4624496e996..0ff42500de2 100644
--- a/qmake/generators/mac/pbuilder_pbx.cpp
+++ b/qmake/generators/mac/pbuilder_pbx.cpp
@@ -1029,6 +1029,21 @@ ProjectBuilderMakefileGenerator::writeMakeParts(QTextStream &t)
     if (!project->isEmpty("QMAKE_PRE_LINK")) {
         QString phase_key = keyFor("QMAKE_PBX_PRELINK_BUILDPHASE");
         project->values("QMAKE_PBX_BUILDPHASES").append(phase_key);
+
+        ProStringList inputPaths;
+        ProStringList outputPaths;
+        const ProStringList &archs = project->values("QMAKE_XCODE_ARCHS");
+        if (!archs.isEmpty()) {
+            for (int i = 0; i < archs.size(); ++i) {
+                const ProString &arch = archs.at(i);
+                inputPaths << "$(OBJECT_FILE_DIR_$(CURRENT_VARIANT))/" + arch + "/";
+                outputPaths << "$(LINK_FILE_LIST_$(CURRENT_VARIANT)_" + arch + ")";
+            }
+        } else {
+            inputPaths << "$(OBJECT_FILE_DIR_$(CURRENT_VARIANT))/$(CURRENT_ARCH)/";
+            outputPaths << "$(LINK_FILE_LIST_$(CURRENT_VARIANT)_$(CURRENT_ARCH))";
+        }
+
         t << "\t\t" << phase_key << " = {\n"
           << "\t\t\t" << writeSettings("buildActionMask", "2147483647", SettingsNoQuote) << ";\n"
           << "\t\t\t" << writeSettings("files", ProStringList(), SettingsAsList, 4) << ";\n"
@@ -1036,8 +1051,8 @@ ProjectBuilderMakefileGenerator::writeMakeParts(QTextStream &t)
           // resolved dependenices, so we have to ensure that this phase is run after the
           // compilation phase, and before the link phase. Making the phase depend on the
           // object file directory, and "write" to the list of files to link achieves that.
-          << "\t\t\t" << writeSettings("inputPaths", ProStringList("$(OBJECT_FILE_DIR_$(CURRENT_VARIANT))/$(CURRENT_ARCH)/"), SettingsAsList, 4) << ";\n"
-          << "\t\t\t" << writeSettings("outputPaths", ProStringList("$(LINK_FILE_LIST_$(CURRENT_VARIANT)_$(CURRENT_ARCH))"), SettingsAsList, 4) << ";\n"
+          << "\t\t\t" << writeSettings("inputPaths", inputPaths, SettingsAsList, 4) << ";\n"
+          << "\t\t\t" << writeSettings("outputPaths", outputPaths, SettingsAsList, 4) << ";\n"
           << "\t\t\t" << writeSettings("isa", "PBXShellScriptBuildPhase", SettingsNoQuote) << ";\n"
           << "\t\t\t" << writeSettings("runOnlyForDeploymentPostprocessing", "0", SettingsNoQuote) << ";\n"
           << "\t\t\t" << writeSettings("name", "Qt Prelink") << ";\n"
-- 
GitLab