23

I have two targets set up for my app (a lite version and a pro version) and I want to integrate some subtle differences in the code for each of them (e.g. the pro version will not show any iAd banners).

I have been looking around and I see the easiest way to do this is through the use of preprocessor macros. The issue I'm facing is how to set them up in Xcode 4. I want to set up a macro called 'PRO_VERSION' in one target & 'LITE_VERSION' in the other.

Below is an example of how I intend to use them:

#ifdef PRO_VERSION
    // Hide ad banners
#else
    // Show ad banners
#endif
  • Check here: http://stackoverflow.com/questions/5272296/how-to-add-preprocessor-define-globally-for-debug-configuration-in-xcode-4 – Carter Oct 21 '11 at 14:52
  • This is subtly different to what I'm after - Thanks though. –  Oct 21 '11 at 15:07

2 Answers2

40

The build setting you need to change is called 'Preprocessor Macros' and it can be found in the 'Build Settings' tab of the Project Settings pane (use the search box to find it). Select each target in turn in the left-hand side of the Project Settings pane then modify the Preprocessor Macros setting.

The setting is specified as a space-separated list of preprocessor macros in the form 'foo' or 'foo=bar'.

Robin Summerhill
  • 13,695
  • 3
  • 41
  • 37
  • Thanks for your help. Do I need to add them to debug, release or both? –  Oct 21 '11 at 15:02
  • Both. You need your pro and lite versions to compile correctly in debug and release configurations. – Robin Summerhill Oct 21 '11 at 15:11
  • 1
    Just to clarify. You would select your 'Pro' target and then add 'PRO_VERSION' to the Preprocessor Macros setting for both debug and release. You don't need to do anything for the 'Lite' target. – Robin Summerhill Oct 21 '11 at 15:13
  • Is there a way to define something for all configurations? It seems completely wrong to have to duplicate this for debug and release; debug and release should inherit from something, and should only define things that are changes from the shared set. – James Moore Dec 07 '12 at 19:34
3

I'm not on my mac at the moment, so I can't give full step-by-step directions, but I believe this should be accurate, if not as detailed as I would otherwise be. Create a new build target. Go to the configuration screen for this new target. There should be a tab along the lines of compilation options. In this tab there should be a row for other compiler flags. In there, put -DPRO_VERSION.

Kevin
  • 53,822
  • 15
  • 101
  • 132