An XCode build question

Posts: 1,199
Joined: 2004.10
Post: #1
I've been using XCode since the day it appeared for public use, when Panther came out ( which was, amusingly, my birthday Rasp ) -- but I've never really pressed on it too hard, so I can't say I really know it inside and out.

What I'm wondering is if there's a way to have a script run ( or different build phases ) for Development vs Deployment builds.

Basically, I've got a fairly big resources folder for my game. Lots of images, text files, sounds, etc etc. It all ads up ( right now ) to about 10 megs, but will likely at some point be a lot more -- it's annoying because it takes several seconds to copy all the files, and it seems like a waste ( plus, I'm impatient ).

Right now I've got a build phase that runs for both Development and Deployment which copies this folder into the Contents/Resources folder of my app, so my app's self contained. What I'd like is to have that only run on Deployment builds, and have my app ( when in development ) simply refer to the external resources folder. It would be easy enough to have a #ifdef which checks for a debug build and refers to the default folder, ortherwise it refers to the app bundle. But I don't know how to get XCode to run different processes depending on being in Deplyment vs Debug builds.

If I haven't explained this well, I can try to clarify.
Quote this message in a reply
Posts: 365
Joined: 2002.04
Post: #2
Adding a script to be run at build time is easy enough: add a Run Script build phase, double click it and type in your script (or tell it to launch an external script, which can be in any scripting language you like).

Xcode defines some environment variables that your script can examine to determine which kind of build is taking place. Just make your script switch behaviour according to the relevant variables.

Here's a Ruby script which does more or less exactly what you describe, courtesy of OneSadCookie:

def execute(command)

$resources_dir =
$contents_dir =  File.dirname($resources_dir)
$source_dir = ENV['SOURCE_ROOT']

execute("rm -rf '#{$resources_dir}'")
execute("mkdir -p '#{$contents_dir}'")

if ENV['BUILD_STYLE'] == 'Development' then
    execute("ln -sf '#{$source_dir}/Resources' '#{$resources_dir}'")
    execute("tar -c --exclude-from FileExclusions.txt '.svn' Resources | tar -x --directory '#{$contents_dir}'")
There's probably a list of environment variable names defined by Xcode somewhere, but I certainly can't find it. Huh

EDIT: well, there's [url=]this[/url], but it doesn't list the aforementioned BUILD_STYLE, and I don't think BUILD_VARIANTS is the same thing.

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Posts: 1,199
Joined: 2004.10
Post: #3
This looks like it could work, but I'll admit, I don't know Ruby. Ought to be able to figure it out from here, though.

Quote this message in a reply
Posts: 22
Joined: 2005.02
Post: #4
I have also tried to #ifdef code if it's debug code. My solution: There is a field named 'Preprocessor macros'. There you define the symbol DEBUG (or whatever you like) only in the debug configuration. Then you can write code which checks for it with #ifdef
Quote this message in a reply
Posts: 1,199
Joined: 2004.10
Post: #5
Thanks -- I already knew about that one though. Basically, I've got this in my main()

    #ifdef DEBUG
    setResourcePath( "/Users/zakariya/Projects/WorldEngine/Resources" );
    setResourcePath( OSX_AppResourcePath() );

What I want is to have the resource tree copied into the app bundle *only* when I'm building a Deployment build.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Question : Deploy xcode 3.1.3 to ios 5+ ? papaonn 6 10,611 Apr 12, 2012 08:37 PM
Last Post: MattDiamond
  xcode build optimizations NelsonMandella 5 10,265 Jul 24, 2009 06:39 AM
Last Post: Oddity007
  XCode doesn't realize a library has changed unless you force your project to build. XSTNX 6 8,842 Jun 8, 2009 10:25 AM
Last Post: XSTNX
  xcode build problem NelsonMandella 7 8,426 Apr 13, 2009 12:21 PM
Last Post: szymczyk
  Stupid xcode question: How do I turn off precompiled headers? SourceIT 2 10,970 Aug 30, 2008 12:53 PM
Last Post: SourceIT