qt5base-lts/mkspecs/features/mac/unsupported/objc_namespace.prf
Tor Arne Vestbø f24536f8a5 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>
2016-01-29 14:41:21 +00:00

51 lines
2.0 KiB
Plaintext

#
# 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