开发者

Programmatically determine active configuration

开发者 https://www.devze.com 2023-01-16 06:15 出处:网络
Is there a way to determine the active configuration (that means Debug or Release) in code? Something along the lines of

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.


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


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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消