Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xcode different linker/cflags for device vs simulator on same target?

Tags:

xcode

iphone

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

like image 809
drunknbass Avatar asked Jun 22 '10 19:06

drunknbass


1 Answers

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

like image 74
nevyn Avatar answered Oct 05 '22 22:10

nevyn