Building Xcode 4 projects from the command line

Posted on by in Development

The Xcode 4 developer tools introduced some changes to the xcodebuild command line tool. Instead of specifying a project and target developers can now provide a workspace and scheme to build.

> /Developer_Xcode4/usr/bin/xcodebuild -help
Usage: xcodebuild [-project ] [[-target ]…|-alltargets] [-configuration ] [-arch ]… [-sdk [|]] [=]… []…
xcodebuild -workspace -scheme [-configuration ] [-arch ]… [-sdk [|]] [=]… []…
xcodebuild -version [-sdk [|] [] ]
xcodebuild -list [[-project ]|[-workspace ]]
xcodebuild -showsdks

The workspace and scheme names should be known from the project. The default configuration options are “Debug” and “Release”. The “-showsdks” option lists available SDKs.

> /Developer_Xcode4/usr/bin/xcodebuild -showsdks
Mac OS X SDKs:
Mac OS X 10.6 -sdk macosx10.6

iOS SDKs:
iOS 4.3 -sdk iphoneos4.3

iOS Simulator SDKs:
Simulator – iOS 3.2 -sdk iphonesimulator3.2
Simulator – iOS 4.0 -sdk iphonesimulator4.0
Simulator – iOS 4.1 -sdk iphonesimulator4.1
Simulator – iOS 4.2 -sdk iphonesimulator4.2
Simulator – iOS 4.3 -sdk iphonesimulator4.3

Available build actions are listed in the xcodebuild man pages. Unfortunately these do not match the actions available in a scheme and the command line does not provide a mechanism for testing, running, profiling, or analyzing builds.

> man xcodebuild

buildaction …
Specify a build action (or actions) to perform on the target. Available build actions are:

build Build the target in the build root (SYMROOT). This is the default build action.

archive Archive a scheme from the build root (SYMROOT). This requires specifying a workspace and scheme.

installsrc Copy the source of the project to the source root (SRCROOT).

install Build the target and install it into the target’s installation directory in the distribution root (DSTROOT).

clean Remove build products and intermediate files from the build root (SYMROOT).

Given all of these configuration options it is then possible to perform builds from the command line.

> /Developer_Xcode4/usr/bin/xcodebuild -workspace WrappingScrollView.xcworkspace -scheme WrappingScrollViewDemo -sdk iphonesimulator4.3 -configuration Debug clean build
Build settings from command line:
SDKROOT = iphonesimulator4.3

=== CLEAN NATIVE TARGET JCFWrappingScrollView OF PROJECT JCFWrappingScrollView WITH CONFIGURATION Debug ===
Check dependencies

** CLEAN SUCCEEDED **

=== BUILD NATIVE TARGET JCFWrappingScrollView OF PROJECT JCFWrappingScrollView WITH CONFIGURATION Debug ===
Check dependencies

ProcessPCH /Users/Jonah/Library/Developer/Xcode/DerivedData/WrappingScrollView-fqscqfdtpoqunuanehtbgpseirdj/Build/PrecompiledHeaders/JCFWrappingScrollView-Prefix-dkkjrdaonxokgpbkgjfmpmcpadoz/JCFWrappingScrollView-Prefix.pch.gch JCFWrappingScrollView/JCFWrappingScrollView-Prefix.pch normal i386 objective-c com.apple.compilers.llvmgcc42
cd /Users/Jonah/Desktop/WrappingScrollView/JCFWrappingScrollView
setenv LANG en_US.US-ASCII

** BUILD SUCCEEDED **

Hopefully that is sufficient to automatically produce ad-hoc builds on a continuous integration server.