Building Xcode 4 projects from the command line

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

Check dependencies


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
cd /Users/Jonah/Desktop/WrappingScrollView/JCFWrappingScrollView
setenv LANG en_US.US-ASCII


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

This entry was posted in Mobile and tagged , , , , . Bookmark the permalink.

11 Responses to Building Xcode 4 projects from the command line

  1. Pingback: Running Xcode 4 unit tests from the command line | Carbon Five Community

  2. Pingback: Automated ad hoc builds using Xcode 4 | Carbon Five Community

  3. his says:

    Is there a way to add a file or folder to an Xcode project via the Xcode command line?

  4. Jonah Williams says:

    @his: nothing that I have found. It might be possible to do so via Xcode’s scripting interface or by editing the project file xml directly but I don’t think either one is well supported or documented.

  5. lou says:

    Very interesting; but I was wondering if there is any other way to use the IDE and automate it (this would give you capability for example to launch a target that uses the simulator, something that Xcodebuild cannot do).

    Looked at Applescript but it doesn’t seems to work with Xcode4, you can cheat using keyboard shortcut but at that point you loose capability to get back the results of the build and whatever is printed in the log.

    Jonah, do you know of any way to actually drive the Xcode4 IDE via UI instead than console? Thanks!

  6. shankar Shinde says:

    Hi Jonah,
    Thanks for useful post. short and sweet info it goes direct to solution. This help me for workspace.
    Still i am looking for using -project option.

  7. Pingback: » 幅優先探索すら知らない素人がDevQuizで満点を取るまでの話..ほかニュース32件(09月30日) |

  8. Jay says:


    Is there a way to specify to provisioning profile or do you have to resign it through the codesign tool?



  9. Ferry says:

    When using the archive build action, is there a way to specify the the directory it will create the archive in?

  10. suvarna says:

    Is it possible to specify bundle identifier using command line(xcodebuild)?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>