summaryrefslogtreecommitdiffstats
path: root/mkspecs/features/mac
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>2015-09-27 23:30:41 +0200
committerTor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>2016-01-29 14:41:21 +0000
commitf24536f8a533a3001c3a142f9d5c4bc4036bc5bf (patch)
tree296fde80f7f8425033c3f596583ef3c7a40b8f79 /mkspecs/features/mac
parent50489f2e41b42ae391580a01e76f255ae98de1cf (diff)
Add tool to namespace Objective-C classes at link time
The feature is enabled by CONFIG += unsupported/objc_namespace, but can be easily integrated into other build systems such as CMake or native Xcode by modifying the LD and LDFLAGS equivalent for each build system. This is a less resource-intensive alternative to using multiple Qt builds with different -qtnamespace settings. Note: The feature is not supported in any way, and should be used with care. Change-Id: Ibb8ba1159db36efd7106c117cc2210c7e2e24784 Reviewed-by: Martin Smith <martin.smith@theqtcompany.com> Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
Diffstat (limited to 'mkspecs/features/mac')
-rw-r--r--mkspecs/features/mac/unsupported/objc_namespace.prf50
1 files changed, 50 insertions, 0 deletions
diff --git a/mkspecs/features/mac/unsupported/objc_namespace.prf b/mkspecs/features/mac/unsupported/objc_namespace.prf
new file mode 100644
index 0000000000..94e0fbe0de
--- /dev/null
+++ b/mkspecs/features/mac/unsupported/objc_namespace.prf
@@ -0,0 +1,50 @@
+#
+# W A R N I N G
+# -------------
+#
+# This file is not part of the Qt API. It exists purely as an
+# implementation detail. It may change from version to version
+# without notice, or even be removed.
+#
+# We mean it.
+#
+
+# The Objective-C runtime will complain when loading a binary that
+# introduces as class name that already exists in the global namespace.
+# This may happen when linking Qt statically into a plugin, and then
+# loading more than two plugins into the same host, both using Qt.
+#
+# We work around this by doing a bit of post-processing on the final
+# binary, adding new suffixed class name entries to the __objc_classname
+# section of the __TEXT segment, and then patching the class_ro_t
+# entries to point to the newly added class names.
+#
+# By linking the binary between these two steps we avoid having to
+# manually remap all the offsets in the Mach-O binary due to the
+# added class names, instead relying on the linker to do this
+# for us by linking in an assembly file with the added names.
+
+objc_namespace_script = $$clean_path($$PWD/../../data/mac/objc_namespace.sh)
+
+isEmpty(QMAKE_OBJC_NAMESPACE_SUFFIX) {
+ QMAKE_OBJC_NAMESPACE_SUFFIX = $$TARGET
+ !isEmpty(QMAKE_TARGET_BUNDLE_PREFIX): \
+ QMAKE_OBJC_NAMESPACE_SUFFIX = $${QMAKE_TARGET_BUNDLE_PREFIX}.$${QMAKE_OBJC_NAMESPACE_SUFFIX}
+}
+
+QMAKE_LFLAGS += \
+ -Wobjc_namespace,--target=$$shell_quote($$TARGET) \
+ -Wobjc_namespace,--suffix=$$shell_quote($$QMAKE_OBJC_NAMESPACE_SUFFIX) \
+ -Wobjc_namespace,--original_ld=$$shell_quote($$QMAKE_LINK)
+
+!isEmpty(QMAKE_OBJC_NAMESPACE_EXCLUDE): \
+ QMAKE_LFLAGS += -Wobjc_namespace,--exclude_list=$$shell_quote($$QMAKE_OBJC_NAMESPACE_EXCLUDE)
+!isEmpty(QMAKE_OBJC_NAMESPACE_EXCLUDE_REGEX) {
+ equals(MAKEFILE_GENERATOR, UNIX): \
+ QMAKE_OBJC_NAMESPACE_EXCLUDE_REGEX ~= s/\\$/\$\$/
+ QMAKE_LFLAGS += -Wobjc_namespace,--exclude_regex=$$shell_quote($$QMAKE_OBJC_NAMESPACE_EXCLUDE_REGEX)
+}
+
+slient: QMAKE_LFLAGS += -Wobjc_namespace,--silent=1
+
+QMAKE_LINK = $$objc_namespace_script