hennes
hennes

Reputation: 9342

Programmatically determine active configuration

Is there a way to determine the active configuration (that means Debug or Release) in code? Something along the lines of

#ifdef XCodeConfigurationDebug
    ...  
#endif  

#ifdef XCodeConfigurationRelease
    ...  
#endif  

I know that it's possible to do this by adding custom compiler flags. However, I'm looking for a more global solution.

Upvotes: 1

Views: 1384

Answers (3)

E. Rivera
E. Rivera

Reputation: 10938

You can also add your own preprocessor macros per configuration on your target's build settings. Ex.:

Debug

GCC_PREPROCESSOR_DEFINITIONS = DEBUG=1

Release

GCC_PREPROCESSOR_DEFINITIONS = RELEASE=1

And then in your code

#ifdef DEBUG
...
#else
...
#endif

Upvotes: 1

vfn
vfn

Reputation: 6066

There is the flag __OPTIMIZE__ that is defined when on RELEASE mode, and so:

#ifndef __OPTIMIZE__
// code for debug mode
#else
// code for release
#endif

Upvotes: 4

justin
justin

Reputation: 104698

i figure it out using the preprocessor declarations. you can add your own definition, or NDEBUG is another common one to declare in release.

Upvotes: 2

Related Questions