From ef4ef2884d3b3e26083ee71df37cd5efde4cffe9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?=
 <tor.arne.vestbo@theqtcompany.com>
Date: Wed, 3 Jun 2015 14:05:56 +0200
Subject: [PATCH] Use absolute rpath to Qt libraries for non-prefix builds
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Task-number: QTBUG-46391
Change-Id: Iaebba29c340fb027e23a0923f3692d47f9d450d5
Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com>
---
 mkspecs/features/mac/default_post.prf | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/mkspecs/features/mac/default_post.prf b/mkspecs/features/mac/default_post.prf
index 246c9c60e69..b459389c720 100644
--- a/mkspecs/features/mac/default_post.prf
+++ b/mkspecs/features/mac/default_post.prf
@@ -40,15 +40,13 @@ qt:!isEmpty(QT_CONFIG) {
     # libraries. This applies only to apps, since all loaded libraries inherit
     # rpaths from current process executable.
     else:!if(host_build:force_bootstrap):equals(TEMPLATE, app):!defined(QMAKE_RPATHDIR, var):contains(QT_CONFIG, rpath) {
-        # If app is outside of Qt SDK prefix use absolute path to Qt libraries,
-        # otherwise make it relative, so all SDK tools and examples work when
-        # relocated.
-        # Tests are an exception, since they are launched in their build not
-        # install location by CI, so we cannot use relative rpaths there.
-        if(!contains(target.path, "$$re_escape($$[QT_INSTALL_PREFIX])/.*")|\
-            contains(target.path, "$$re_escape($$[QT_INSTALL_TESTS])/.*")) {
-            QMAKE_RPATHDIR = $$[QT_INSTALL_LIBS]
-        } else {
+        # If app is expected to be installed into the Qt prefix build, use
+        # relative path, so all SDK tools and examples work when relocated.
+        prefix_build:defined(target.path, var):\
+            contains(target.path, "$$re_escape($$[QT_INSTALL_PREFIX])/.*"):\
+            # Tests are an exception, since they are launched in their build not
+            # install location by CI, so we cannot use relative rpaths there.
+            !contains(target.path, "$$re_escape($$[QT_INSTALL_TESTS])/.*") {
             app_bundle {
                 ios:  binpath = $$target.path/$${TARGET}.app
                 else: binpath = $$target.path/$${TARGET}.app/Contents/MacOS
@@ -57,6 +55,9 @@ qt:!isEmpty(QT_CONFIG) {
             }
             QMAKE_RPATHDIR = @loader_path/$$relative_path($$[QT_INSTALL_LIBS], $$binpath)
             unset(binpath)
+        } else {
+             # Otherwise, use absolute path to Qt libraries
+             QMAKE_RPATHDIR = $$[QT_INSTALL_LIBS]
         }
     }
 }
-- 
GitLab