Xcode - Pre / Post build tasks
Wednesday, October 19, 2011 at 6:22PM If you have ever wanted to run some scripts as part of an Xcode build, it's easier than you think with version 4. Follow these brief instructions to add custom tasks to your build process.
Firstly select the project file in the navigator, then select the target you wish to add a task to. Then select the "Build Phases" tab.
By default you will be presented with the following four "build phases":
Those are the steps which Xcode performs to convert the code you type in it into the code which your computer can understand.
Click the "Add Build Phase" button and select "Add Run Script" to add your own item to the "build phases" list.
The approach Xcode seems to want you to take is to type your script directory into this screen. If you do opt for that approach then there is a whole lot of placeholder values that are provided to you which can make life much easier.
The other fields on that screen will be immediately familiar (their purpose) to anyone who has done some shell scripting, so there is no need to explain them.
Some notes:
- Documentation on the placeholder values.
- You can rename the build phase by double clicking its title (you can see above that I have renamed mine to "Run Script - Compile Fact List".
- Drag the build to be in the order which you would like it to be for formed. (This can make it a pre-build task or a port-build task.)
- The script will be run from the root directory of your project.