Xcode 4 : define a preprocessor macro in a dependent target
I have an app named MyApp which is linked to a static library MyLibrary I've ad开发者_JS百科ded the MyLibrary project to Xcode and added the MyLibrary target to MyApp's target dependencies. All this works fine, I can set breakpoints, and I'm pretty happy.
The thing is that I want a conditional log in the library :
#ifdef DEBUG
# define MYDebug(msg, ...) NSLog(@"\nDEBUG -> %@ \n(%s:%d)",[NSString stringWithFormat:msg, ## __VA_ARGS__], __PRETTY_FUNCTION__,__LINE__);
#else
# define MYDebug(msg, ...)
#endif
So I have two build configuration for my library : - Debug has "DEBUG=1" in the target's build settings in "preprocessor macros" - Prod has nothing
And the MyLibrary target is set to build with the Debug build configuration.
This works fine if I build the static library (.a), and include it in a project. But if it is built by target dependency, it seems that DEBUG is not defined (MYDebug doesn't log anything).
I've also tried to set DEBUG=1 in MyApp's build settings, but it doesn't work.
Is there something I missed, or another way to do it ?
It should just be "DEBUG" instead of "DEBUG=1". Also, to use a macro that needs an Object assignment (NSString, etc) you need to escape most of the characters like @
and "
etc..
Here is a screenshot of a working project of mine from xCode 4.1:
精彩评论