Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
objcnamemangler-cmake.qdoc
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5\group cmake-commands-qtbuildtools
6\title CMake Commands in Qt6 BuildTools
7
8The following CMake commands are defined when Qt6::BuildTools is loaded, for instance
9with
10
11\code
12find_package(Qt6 REQUIRED COMPONENTS BuildTools)
13\endcode
14
15\sa{CMake Command Reference}
16*/
17
18/*!
19\page qttools-cmake-qt-mangle-objc-symbols.html
20\ingroup cmake-commands-qtbuildtools
21
22\title qt_mangle_objc_symbols
23\keyword qt_mangle_objc_symbols()
24
25\summary {Mangles Objective-C class and category names in a target's binary.}
26
27The command is defined in the \c BuildTools component of the \c Qt6 package.
28Load the package with:
29
30\code
31find_package(Qt6 REQUIRED COMPONENTS BuildTools)
32\endcode
33
34\cmakecommandsince 6.12
35\preliminarycmakecommand
36
37\section1 Synopsis
38
39\badcode
40qt_mangle_objc_symbols(target
41 (OLD_NAMESPACE namespace | USE_QT_NAMESPACE_AS_OLD)
42 (NEW_NAMESPACE replacement | GENERATE_RANDOM_NEW_NAMESPACE)
43 [EXCLUDE_CLASSES class...]
44 [QUIET]
45 [CODESIGN]
46 [CODESIGN_IDENTITY identity]
47)
48\endcode
49
50\versionlessCMakeCommandsNote qt6_mangle_objc_symbols()
51
52\section1 Description
53
54Mangles Objective-C class and category names in the \c target binary by
55replacing the specified namespace with either a provided replacement string
56or a unique random string of the same length.
57
58This is useful when statically linking multiple libraries that each embed
59their own copy of the Objective-C runtime information for the same class
60names, which would otherwise clash at load time.
61
62This command adds a \c POST_BUILD step to \c target. Note that this step
63potentially invalidates code signatures, so custom codesigning needs to be
64installed after the name mangling (for example, using the \c CODESIGN
65option). The \c POST_BUILD step:
66
67\list 1
68 \li Mangles Objective-C symbols by replacing the namespace.
69 \li Optionally re-signs the binary if \c CODESIGN is specified.
70\endlist
71
72The replacement string must be the same length as the original namespace for
73binary safety. When \c GENERATE_RANDOM_NEW_NAMESPACE is used, a random string
74of the same length is automatically generated. When using
75\c USE_QT_NAMESPACE_AS_OLD with \c NEW_NAMESPACE, if the replacement is
76shorter than the Qt namespace, it will be padded with underscores; if longer,
77a warning will be issued and the replacement will be truncated.
78
79Objective-C symbol mangling is only supported on Apple platforms. On other
80platforms, this command issues a warning (unless \c QUIET is given) and does
81nothing.
82
83\section1 Arguments
84
85\c target is the target whose binary will be patched.
86
87\c OLD_NAMESPACE is the namespace prefix to replace, for example
88\c{"AcmeApp"} or \c{"MyNamespace"}.
89
90\c USE_QT_NAMESPACE_AS_OLD uses the Qt namespace read from
91\c{Qt::Core}'s \c QT_NAMESPACE property instead of an explicit
92\c OLD_NAMESPACE.
93
94\c NEW_NAMESPACE is the replacement string. With \c OLD_NAMESPACE, it must be
95the same length as \c OLD_NAMESPACE. With \c USE_QT_NAMESPACE_AS_OLD, it will
96be padded with underscores if shorter, or truncated with a warning if
97longer.
98
99\c GENERATE_RANDOM_NEW_NAMESPACE generates a random replacement string
100instead of an explicit \c NEW_NAMESPACE.
101
102\c EXCLUDE_CLASSES lists class names to exclude from mangling. May be
103specified multiple times.
104
105\c QUIET suppresses output from the mangler tool.
106
107\c CODESIGN re-signs the binary after mangling (macOS only).
108
109\c CODESIGN_IDENTITY sets the code signing identity to use. Defaults to
110\c{"-"} for ad-hoc signing.
111
112\section1 Examples
113
114With an explicit replacement:
115
116\badcode
117qt_mangle_objc_symbols(MyApp
118 OLD_NAMESPACE "AcmeApp"
119 NEW_NAMESPACE "ACMEAPP"
120 CODESIGN
121)
122\endcode
123
124With a random namespace:
125
126\badcode
127qt_mangle_objc_symbols(MyApp
128 OLD_NAMESPACE "AcmeApp"
129 GENERATE_RANDOM_NEW_NAMESPACE
130 CODESIGN
131)
132\endcode
133
134With excluded classes:
135
136\badcode
137qt_mangle_objc_symbols(MyApp
138 OLD_NAMESPACE "AcmeApp"
139 NEW_NAMESPACE "ACMEAPP"
140 EXCLUDE_CLASSES AcmeApp_Internal AcmeApp_Private
141 CODESIGN
142)
143\endcode
144
145Using the Qt namespace from \c{Qt::Core}:
146
147\badcode
148qt_mangle_objc_symbols(MyApp
149 USE_QT_NAMESPACE_AS_OLD
150 NEW_NAMESPACE "MyNS"
151 CODESIGN
152)
153\endcode
154*/