17

I currently have a number of special "flavors" of an iPhone application that I need to build. Ideally, I would like to have a scheme for each "flavor" and each scheme would define (or set) one or more preprocessor definitions that I can use to branch on in my code and possibly even preprocess my info.plist file. This can obviously be done with multiple targets, but since I could have many different "flavors" of the app, it would be great to do it with schemes to keep the target count down. My current thought is to add these preprocessor definitions during a pre-action script, but I can not for the life of me find any way to update GCC_PREPROCESSOR_DEFINITIONS. Since it is an environment variable, shouldn't I have access to append onto GCC_PREPROCESSOR_DEFINITIONS?

1

4 Answers 4

15

Worse case scenario you can do a pre-build script for the scheme. You'll have to include the script for every scheme though:

I would prefer to attach it to a Configuration:

Then you can easily add preprocessor macros for the various configurations, like I have here for Debug:

The <ProjectName>_Prefix.pch file is a great place to put macros that effect the whole program, like I have here:

In my example we're effectively turning off console output when not in debug mode, providing a little speed boost.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Dustin. I want to reduce the number of configurations if at all possible. Good tip about the console output though.
All of your links are broken :(
10

To meet my requirement of allowing schemes to set preprocessor definitions, the best solution I have come up with is to have scheme pre-action and post-action scripts modify a xcconfig file. This file, in turn, updates the build configuration, setting the preprocessor definitions and will even allow me to define preprocessor definitions to conditionally modify the info.plist. If anyone else goes down this route, make sure you take into account how this file is handled by source control.

This article's question and associated answers was helpful to me: How to append values in xcconfig variables?

1 Comment

Hi Christopher, can you expand on this? How do you modify the xcconfig file?
0

How about defining multiple targets and defining pre-processor macros in the target-specific build options? Then you need only have one scheme, and you can build all the targets in one shot, all with their own specific build configurations.

1 Comment

Thanks for the suggestion. For some people, this may be a good solution. For this specific project, due to the scale and number of "flavors" I will need, this would be difficult to maintain.
0

If I understood your question correctly, you are looking to add some of user defined preprocessor macros to your source code, there is a way to add them in your target using Xcode. (e.g. GCC_PREPROCESSOR_DEFINITIONS = USE_TAPJOY )

Step 1) Decide marco name e.g USE_TAPJOY Step 2) Go to target-> select tab "Build Setting" (Make sure all tab is enabled) Step 3) in search box search for "Preprocessor Macro") Step 4) Check for Debug/Release section Step 5) Enter your Marco there enter image description here

Step 6) Use this macro in your source code as below

For conditional include 

    #ifdef USE_TAPJOY
    #import <Tapjoy/Tapjoy.h>
    #endif

    For conditional source code
    #ifdef USE_TAPJOY        // Tapjoy Connect Notifications
            [[NSNotificationCenter defaultCenter] addObserver:self
                                                     selector:@selector(tjcConnectSuccess:)
                                                         name:TJC_CONNECT_SUCCESS
                                                       object:nil];
            [[NSNotificationCenter defaultCenter] addObserver:self
                                                     selector:@selector(tjcConnectFail:)
                                                         name:TJC_CONNECT_FAILED
                                                       object:nil];
    #endif

Good luck

1 Comment

This was not the question. Question was the ability to set for each scheme a different Macro, while keeping only one target.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.