tags:

views:

34

answers:

1

anyone know if its possible to set cflags/linker flags different for simulator vs device on the same build target in xcode.

+1  A: 

In an .xcconfig file, you can have

OTHER_CFLAGS[sdk=iphoneos*] = foobar
OTHER_CFLAGS[sdk=iphonesimulator*] = barfoo

Any build setting can be conditional on a number of things, for example the shortname for an sdk. The device SDKs are named iphoneos-4.0 for example, and sim iphonesimulator-4.0. The above thus gets you the 'foobar' as CFLAG for the device, and 'barfoo' for the sim.

To get started with xcconfigs quickly:

  1. New file > Other > Configuration Settings File
  2. Open the project or target editor (cmd-alt-E for the target one)
  3. Select a setting you want to customize (like cflags), and copy it with cmd-c
  4. Paste in the new xcconfig file
  5. Modify as above
  6. In your project or target editor's lower right corner, select your xcconfig file as "Based On".

Notice how the build settings UI now lets you edit the conditionals... You can create new conditionals with the lower left button, but it won't let you set "iphoneos*" for example, only specific versions.

Note that the magical $(inherited) lets you make a setting that inherits project settings but overrides just a part of it, like so:

OTHER_CFLAGS[sdk=iphoneos*] = $(inherited) foobar
OTHER_CFLAGS[sdk=iphonesimulator*] = $(inherited) barfoo

I don't know a good resource for xcconfigs, but this'll get you started anyway: http://robnapier.net/blog/build-system-1-build-panel-360#more-360

Joachim Bengtsson
ha i just read that, thx! just what i needed.
drunknbass
after doing this in my dropdown i lost the option to build for simulator :/ know offhand a way to get that option back?
drunknbass
ok turns out that xcode doesnt like having the BASE_SDK set in the xcconfig file. if you totally remove it from build settings the dropdown doesnt ive you a choice what basesdk to compile against (simulator or device)
drunknbass