theDuncs
theDuncs

Reputation: 4843

How to specify #define commands for my two different targets

I have a project I am splitting into two targets. The original single-target project uses a number of define commands, however I need these values to now be different depending on which target I am building.

What's the correct way to do that? Should I be using NStrings declared on the AppDelegate? Or can I use a #if statement when settings the #defines?

Any help, much appreciated.

Upvotes: 5

Views: 854

Answers (2)

justin
justin

Reputation: 104708

One approach would be like this:

#if defined(MON_TARGET_A)
  #define MON_TARGET_NAME "App A"
#elif defined(MON_TARGET_B)
  #define MON_TARGET_NAME "App B"
#else
  #error "which target are you building?"
#endif

Then add MON_TARGET_A or MON_TARGET_B to your target's preprocessor settings.

Usually, you'll use GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS and not GCC_PREPROCESSOR_DEFINITIONS because the latter can prevent sharing of PCH headers.

To add this, go to:

  • Project Navigator -> Project -> Target -> Build Settings

then drop GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS into the search field and set its value to something like: MON_TARGET_A $(inherited)

Upvotes: 3

Max
Max

Reputation: 16709

You can add additional preprocessor macros in your target settings (Preprocessing->Preprocessor Macros) and use #ifdef.

This is the most flexible approach.

Upvotes: 1

Related Questions