How to specify #define commands for my two different targets

后端 未结 2 1782
感动是毒
感动是毒 2021-01-13 05:04

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 depen

相关标签:
2条回答
  • 2021-01-13 05:37

    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)

    0 讨论(0)
  • 2021-01-13 05:38

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

    This is the most flexible approach.

    0 讨论(0)
提交回复
热议问题