Separate build directory using xcodebuild

xcodebuild build-for-testing
run xcode project from terminal
xcodebuild symroot
output dir
xcode binary output directory
xcodebuild xcconfig
xcodebuild is trying to install apple-provided software
xcodebuild archivepath

The man page for xcodebuild reads:

Run xcodebuild from the directory containing your project (i.e. the directory containing the projectname.xcodeproj package).

I would like to keep my source directory (which is a Subversion external) clean and unmodified, and build my object files and executables to a location completely outside of the source directory.

Is there any way to build into a separate build directory from a terminal using xcodebuild like you can do with make tools or even msbuild on Windows?

xcodebuild: how to really change its build path, to StackOverflow topic: Separate build directory using xcodebuild. Background: I build my tests from both Xcode and command line. This is short one-solution-post that is longer version of my answer to this StackOverflow topic: Separate build directory using xcodebuild. Background: I build my tests from both Xcode and command line.

To achieve complete separation the following build settings have to be changed (more than just CONFIGURATION_BUILD_DIR like accepted answer suggests), otherwise Xcode still builds some of its artifacts under its default build folder.

On my machine Xcode normally builds everything to ./Build and ./DerivedData where current directory is one of my project.

I wanted xcodebuild to build everything under Build-command-line folder so I used xcodebuild -scheme MyScheme -showBuildSettings | grep Build\/ to find all build settings that correspond to all build paths and by trial-end-error I found "the generative" build settings that are enough to redirect all build artefacts produced by xcodebuild to custom folder.

I ended up using the following command:


xcodebuild -project MyProject.xcodeproj \
         -IDEBuildOperationMaxNumberOfConcurrentCompileTasks=`sysctl -n hw.ncpu` \
         -scheme MyScheme \
         -sdk iphonesimulator \
         -destination 'platform=iOS Simulator,name=iPhone 6S Plus,OS=latest' \
         -xcconfig command-line-build.xcconfig \
         -derivedDataPath $(DERIVED_DATA_DIR) \

Where command-line-build.xcconfig is:


// Paths
// the following paths are enough to redirect everything to $HERE_BUILD
MODULE_CACHE_DIR    = $(HERE_BUILD)/DerivedData/ModuleCache

Note: Make sure you use absolute paths in your xcconfig, otherwise you may have error: Xcode crashing on startup "parentPath must be nil but it is not.

I have written a post about this solution with a bit of background: xcodebuild: how to really change its build path.

P.S. Of course this information is subject to change but as of Xcode Version 7.3.1 (7D1014) it works perfectly for me.

Technical Note TN2339: Building from the Command Line with , Describes the build settings used in the Xcode build system to compile source code and produce binary files. (Required) Enter a space-delimited list of actions. Valid options are build, clean, test, analyze, and archive. For example, clean build will run a clean build. See Apple: Building from the command line with Xcode FAQ. Default value: build configuration Configuration (Optional) Enter the Xcode project or workspace configuration to be built.

In my project, setting SYMROOT turned out to be sufficient to build the project in a different location, leaving other locations untouched.

From Apple's Xcode Build Setting Reference (which I came across via another answer here, thanks!):

SYMROOT (Build Products Path)

Description: Directory path. Identifies the root of the directory hierarchy that contains product files and intermediate build files. Product and build files are placed in subdirectories of this directory.



This setting is also mentioned a few times in the xcodebuild man page:

Available actions are:

build: Build the target in the build root (SYMROOT)...

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

Build Setting Reference, The build location preference that you configure in Xcode is stored in the Each location type follows different patterns for composing the path used for builds. In Xcode, the Configurations section of your project's Info pane provides a pop-up menu, which sets the default configuration to be used by xcodebuild when building a target. Use this pop-up menu to select a default build configuration for xcodebuild as seen in Figure 2. Figure 2 Debug set as the default build configuration for xcodebuild.

Xcode 10

For a Workspace if you're using CocoaPods:

xcodebuild -workspace youProject.xcworkspace -scheme yourScheme -sdk iphonesimulator -configuration Release SYMROOT=$(PWD)/build

That will put your .app in ./build/Release-iphonesimulator

Xcode Build Locations, It seems that if you call xcodebuild command from the command line as betabuilder does all the build and not in the DerivedData folder. wasn't able to read the output because it expect the build output in a different folder  This post shares various ways to use xcodebuild to build your iOS or OS X projects from the command line. The easiest way is just type a single command without any parameter "xcodebuild" to build the project in the current directory: xcodebuild The output is below (GCClient here is the target of my project): === BUILD TARGET GCClient OF PROJECT GCClient WITH THE DEFAULT CONFIGURATION (Release

You should set the SYMROOT build setting to your desired location. All of the other relevant build settings are derived from it.

Xcodebuild create the build output in the same dir · Issue #29 , Managing different Environments using XCode Build Schemes and built in the same directory, referred to as the workspace build directory  GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. Build Xcode schemes in Atom using `xcodebuild`. Use Git or checkout with SVN using the web URL.

Managing different Environments using XCode Build Schemes and , To run an Xcode build, you need to have one or more build agents running macOS with installed Xcode. Working with different Xcode setups required version in the "Path to Xcode" setting (see below) of the Xcode Project build step settings. We can build an iOS app using xcodebuild ‘build’ action which generate the derived data for our iOS app. Once app is build, it can run inside the simulator or can be used by test bundle.

Xcode Project - Help, Usage To build an Xcode project, run xcodebuild from the directory containing By default, xcodebuild builds the first target listed in the project, with the default  Information like bitcode, dsyms upload, team information. All are specified in exportOptions. Run ‘xcodebuild –help’ for more all options available for exportOptions. In the demo app, the build script can build for Debug, Staging and Release. Release builds use the store.plist – all the others use adhoc.plist. a bonus: cocoapods!

man page xcodebuild section 1, By default, a separate file will be written for each architecture and build variant, and these will be generated in the Intermediates directory for the target whose  The binary folder is where CMake generates the build pipeline. You can create the binary folder anywhere you want. A common practice is to create a subdirectory build beneath CMakeLists.txt. By keeping the binary folder separate from the source, you can delete the binary folder at any time to get back to a clean slate.

  • I found that I also needed to set CONFIGURATION_TEMP_DIR, and then this worked for me.
  • You can just set BUILD_DIR and that will work too :D
  • Stanislav, you may be (the only person :) ) who knows this one :O
  • No, I don’t. Sorry :)
  • If you want to redirect everything to a custom folder, at least OBJROOT is very important because quite a few of folders depend on it, not on SYMROOT. I have just checked Xcode 7.3.1 - MODULE_CACHE_DIR and SHARED_PRECOMPS_DIR are also independent of SYMROOT. So your answer will still build some stuff to default build directory however maybe that is enough for your task.