May 26, 2011

Command Line Building using Xcode

Posted in Uncategorized at 8:42 pm by tetontech

Most professional software development companies or professional software organizations within companies eventually need to be able to build their products from the command line as part of an automated build process.  Usually this is proceeded by doing a pull from a software repository.  Often such builds are done at night or during other off-time hours.

This posting will not cover the use of git or other repositories.  It will cover the use of the terminal to build an Xcode project in Xcode 4.  Most of this information has been gleaned from examining the man page of xcodebuild.  You can see the help for xcodebuild if in the terminal you enter man xcodebuild.

Getting the version of xcode

Often in scripts a check of the compilation tool version is done to ensure correct compilation.  This is done by calling xcodebuild -version

Listing available sdks

                It is possible that you may need your script to check for a specific SDK version prior to triggering a compilation of your code.  This uses the xcodebuild -showsdks call.

Listing available schemes in a workspace

               If you have a workspace that has many projects in it t is, again, wise to check if a scheme for the project you want to compile exists.  Each project has a scheme, by default, in Xcode 4.  Here is the call to list schemes available in a workspace.  xcodebuild -list -workspace <full path to workspace file>
                The example shown here lists the schemes from the Examples.xcodeworkspace found in the QuickConnect 2.x download.

Listing available targets in a project

                If you are using a project that is or is not independent of a workspace your script may need to check to make sure that the correct target is available in the project since a project can have any number of targets.  The command to list targets is xcodebuild -list -project <full path to project file>
The example here lists the targets available in the File List project as well as the build configurations available.

Building all projects in a workspace

                To do this you would need to call each project individually or, and this may or may not be much better in the case of you projects, build dependencies into the xcode projects and then trigger the building of them all by building the topmost build.  This would be the one that has dependencies on the others.

Building a project in a workspace

                To do this what you really do is to either build the project directly without the workspace involved (see Building a project that is not part of a workspace below) or build the workspace with a scheme that is specific to your project.  The example shown here is for the second case.  This example builds the File Reader scheme that is part of the File Reader project of the QuickConnect Examples workspace.  I have removed the build output since it had sensitive information regarding the directory structures on my working machine.  The command to build a scheme in a workspace is xcodebuild -workspace <path to workspace file> – scheme <Scheme Name>.

Building a project that is not part of a workspace

                Maybe you need to compile a project without it being in a workspace.  If have cd’ed into the directory and the project is the only xcodeproj file in the directory the command to do this is xcodebuild.  If you are not in the directory the command is xcodebuild -project <path to project>.
                The example shown here is an example of the first.  I have again removed the build results because of the sensitive data exposed regarding the file structure on my machine.

There are many more options available with xcodebuild.  Check out the man page to learn more about targeting platforms, SDK versions, etc.


  1. Mathieu said,

    Thanks mate – useful tips !

  2. suvarna said,

    I want to change bundle idenifier using xcodebuild based on configuration

    for debug bundle identifier is and for release com.zzz.sampelApp

    Any idea?

    • tetontech said,

      I’m sure there is a way to do what you want. I would think it might be accomplished by using a special configuration. I haven’t tried it and have only looked briefly at creating new configurations for this

  3. […] Command Line Building using Xcode […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: