Most of the changes in the build system in Xcode 3.1 relate to the use of SDKs and architectures.
New Base SDK build setting popup
The "SDK Path” build setting has been renamed “Base SDK.” Its value can be either a path or a name of an SDK. When setting the value in the Build Settings Inspector, you choose an installed SDK from a pop-up menu, rather than entering or navigating to an SDK package in the Developer folder.
In .xcconfig
files and when manually editing the SDKROOT
build setting, you can enter either the full path to the SDK or its short name.
If the project is set for Xcode 3.0 or 2.4.1 compatibility, the SDK name will be converted to a path relative to the$DEVELOPER_SDK_DIR
if appropriate. Projects in 3.1 format will store only the SDK short name for better portability in the future.
New Architectures build setting pop-up; new Only Active Architecture checkbox
The “32-bit / 64-bit” Architectures checkboxes have been replaced with a pop-up . The pop-up offers standard configurations of architectures provided by the current SDK, an Other... item to set your custom architecture choices, and any custom architecture choices you have set.
Current projects generally set the Architectures build setting in the Release configuration to ppc i386
and to$(NATIVE_ARCH)
in the Debug configuration, to build a Universal binary for Release but to build only one architecture for debugging.
Starting with Xcode 3.1, project templates are set up to use the Standard architecture in all configurations, so that developers only change the value of Architectures when they change the code model of their code (for example, to add 64-bit support). To speed building for debugging, there is an additional build setting, Build Active Architecture Only. This is checked in Debug configurations, so that the Project ▶ Active Architecture menu controls what architecture is built and launched during debugging.
You can change your projects to follow a similar pattern. This will allow you to change the architecture you debug simply by choosing a different item from the Active Architectures menu, rather than having to change the build settings on all relevant targets in your project.
If the project is set for Xcode 3.0 or 2.4.1 compatibility, the Architectures value will be converted to a concrete build settings if appropriate, and the Only Active Architecture will appear as a custom build setting if the project is opened in those versions of Xcode.
Conditional Build Settings
Xcode 3.0 supported some build settings defined on a per-SDK basis. Xcode 3.1 adds more per-architecture build settings, introduces per-SDK build settings, and adds wildcard matching.
For many build settings, you can select the setting and choose Add Build Setting Condition. An extra line is added to the build setting with popups for Architecture and/or SDK. Pick an architecture or SDK (or “Any Architecture” or “Any SDK”) and set the value. That value will be used only when the conditions of the popup are met.
This allows you to designate certain values to be used only when an override SDK is in use. For example, you can set a preprocessor macro only for builds with the Mac OS X 10.5 SDK, or an optimization flag only for 64 bit architectures
You can specify conditional build settings in .xcconfig files. The syntax to define an architecture-specific setting is:
SETTING_NAME[arch=arch_pattern] = some_value
SETTING_NAME[sdk=sdk_pattern] = some_value
SETTING_NAME[sdk=sdk_pattern, arch=arch_pattern] = some_value
where arch_pattern
and sdk_pattern
architecture or SDK names you would enter into the ARCHS
and SDKROOT build settings.
The values on the right-hand side of the equals sign may be glob patterns, such as *64*
or macosx10.5*
. These patterns will use the given value for any architecture and SDK that match the pattern. Note that these are shell match patterns, not regular expressions. In Xcode-1059 and later, a pattern that matches the SDK that represents the current OS (for example,sdk=macosx10.5
implicitly matches when the SDKROOT
is unset or set to “” or “/”.
Compiler Version build setting
The GCC_VERSION
build setting is now present by default in the Build Settings pane, and allows you to set the preferred compiler version to any configured compiler (whether the compiler is installed at the moment or not). You can set the compiler version on a per-configuration basis, and use Conditional Build Settings to use different compiler versions for different architectures or SDKs.
Note that this overrides (and is preferable to) setting the compiler version in the Build Rules inspector pane. Use that pane to use a custom compiler script if necessary, otherwise, the Compiler Version build setting is preferable.
Per-File Build Flags Available to Custom Build Rules
A new build setting, OTHER_INPUT_FILE_FLAGS
, is available to Custom Build Rule scripts. It contains all the flags set in the Build tab of an individual build file.
OpenMP Support
A new Linker build setting allows you to specify OpenMP support. You can override this to pass an explicit path to a library, or to pass a library search path and a -l flag to search for the library by name, whichever is preferable.
Support for Weak Frameworks
You can now designate a given framework to be weak-linked in its entirety. This is different from the weak symbol linking provided by the Deployment Target build setting, which allows your application to launch on systems that don’t have specific symbols defined in your linked frameworks; this allows your application to launch on systems where the framework is completely absent. It is your responsibility to check for this situation at run time and avoid using any symbols in the weak framework, or your program will crash.
To designate a framework as weak-linked, select the framework in the target’s Link Binary With Libraries build phase, choose Get Info, and in the General tab check the Weak Link box. You can also check the Weak box in the Libraries and Frameworks list in the Target inspector when you add libraries and frameworks.
Changes to the Install Mode flags
All previous versions of Xcode and Project Builder used default Install Mode flags of “a-w,a+rX” (write-protected for user, group, and others; readable and executable for user, group, and others.) This caused problems on successive builds, as a user build cannot overwrite a build product from a previous build unless the user has write permission. The default Install Mode permissions have been changed to “u+w,go-w,a+rx” (user write-enabled, group and other write-protected, user, group and other all read- and execute-enabled).
xcodebuild
options
The xcodebuild
command-line tool supports several new options for building Xcode projects from the command line. See its man page for complete details.
-sdk
sdkname allows you to specify an SDK at build time
-find
toolname returns the full path to that tool in the SDK, platform, and version of Xcode in use. This is particularly useful in traditional config files when building against an SDK.