Xcode 4 introduced the DerivedData location. Derived data contains various pieces of data related to Xcode projects, including logs, indexes and build products. The location of the DerivedData folder that Xcode utilises can be configured in a number of places. By default Xcode will use the following path:
This location may also be affected by Xcode’s settings, by your project’s settings, or even by your project’s target settings. Typically this location won’t be of concern when just using Xcode’s GUI to build, run, and archive projects. However, one use case where this can be an issue is for automated builds triggered using the xcodebuild command. Imagine you’ve scripted an automated build that builds your Xcode project and produces build products (e.g. a static library or application binary) which are then packaged and/or distributed elsewhere. It would be difficult to know exactly where the DerivedData folder that contains these build products is located.
One solution is to favour some form of convention. That is, to always use the same location for the DerivedData folder for all your Xcode projects and have this folder hard-coded in your build scripts. The better solution is to tell xcodebuild where to place your build products. xcodebuild can accept build settings, so all we need to do is specify the appropriate setting value. For example:
xcodebuild -configuration Debug CONFIGURATION_BUILD_DIR=/tmp/build
The important piece is the setting of the CONFIGURATION_BUILD_DIR build setting. This allows your script to explicitly define where any build products are placed. In the example build products, including static libraries, application binaries, and dSYM folders would be placed in /tmp/build. Personally I use the following format:
xcodebuild -configuration Debug CONFIGURATION_BUILD_DIR=$SRCROOT/BuildProducts
This will place all the build products in a folder called BuildProducts relative to the project I’m building.