Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 added 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 ?

like image 475
Julien Avatar asked Jul 15 '11 11:07

Julien


1 Answers

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:

enter image description here

like image 83
chown Avatar answered Nov 15 '22 08:11

chown