Information Technology Reference
In-Depth Information
<…code included if MY_TOKEN is defined…>
#endif
NOTE
You can also add tokens to the Preprocessing section. Add them in the same way, but don't prefix them with -D .
Converting build settings into tokens
You can convert any build setting into a token by wrapping it in a dollar sign and either brackets or curly
braces. For example, to read the value of the SDKROOT build setting into your own custom SDK_ROOT token,
use the following:
SDK_ROOT = $(SDKROOT)
You see that Xcode substitutes the real value immediately, so, for example, you may see this:
SDK_ROOT = iphoneos
Unfortunately, you can't do much with this because the value isn't treated as a C string. If you use SDK_ROOT
anywhere, iphoneos is substituted by the preprocessor. The compiler then looks for a symbol called
iphoneos and doesn't find it, because it isn't a true symbol.
You can, however, use this technique to read numerical build settings into your code. But don't forget (again)
that these values are valid at compile-time only.
Conditional compilation is useful for language-, platform-, and target-dependent compilation, but using
compile-time build settings to select runtime code is somewhat eccentric. A more useful alternative is to create
scripts in the build phases and build rules to define how a build proceeds internally.
TIP
To find the name of any build setting, select it in the Build Settings editor, select Edit Copy from the main Xcode
menu, and paste the string into TextEdit. You can select multiple settings at the same time, as long as they don't
take multiple configuration values. For a full list of build settings, see the Xcode Build Setting Reference in the
documentation.
Understanding build phases and build rules
It's worth repeating that Xcode is simply a UI for a set of command-line scripts. The Build Phase and Build
Rules tabs in the build editor define which scripts are run and what they do.
You can view the details of the build—the commands given at the command line and the output they gener-
ate—by selecting the Log navigator, selecting a completed build, and choosing All and All Messages in the tool-
bar at the top of the window. The default terse view shown in Figure 13.28 displays the commands in the order
they were given. As you can see, the sequence in practice isn't as neat as the preprocess⇒compile⇒link⇒copy
template given earlier.
Search WWH ::




Custom Search