Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 322
theDuncs Avatar asked Oct 09 '22 18:10

theDuncs


2 Answers

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)

like image 145
justin Avatar answered Oct 12 '22 00:10

justin


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

This is the most flexible approach.

like image 30
Max Avatar answered Oct 12 '22 02:10

Max