summaryrefslogtreecommitdiffstats
path: root/mkspecs/features/mac/unsupported/objc_namespace.prf
diff options
context:
space:
mode:
Diffstat (limited to 'mkspecs/features/mac/unsupported/objc_namespace.prf')
-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