On May 29, 2008, at 10:54 AM, Brian Stern wrote: On May 29, 2008, at 12:48 PM, Clark Cox wrote:
On Thu, May 29, 2008 at 5:05 AM, Richard Kennaway
<email@hidden> wrote:
How can an XCode program detect whether it was built in Debug or Release
configuration (or any other, for that matter)? In Visual Studio, _DEBUG is
defined as a preprocessor symbol for Debug versions, but I can't find
anything similar in the project settings in XCode, or the docs. I can
manually add _DEBUG to the settings, but that's tedious in a project with a
dozen build targets. Is there anything automatically #defined?
There is no need to add it to a dozen build targets. Add it to the
project, and it will be inherited by all of the targets in said
project.
The whole point of DEBUG/RELEASE macros is that some build configurations #define one and the rest #define the other. It wouldn't make sense to #define DEBUG for all the build configurations in a project (at least not to me).
He meant "define it for the Debug configuration at the project level," which is exactly the right thing to do.
The other thing to do is to command-click to multiple-select only the targets you want to apply this to and choose Get Info. Yes, with a group selection of targets you can set a uniform build setting on all of them at once. Handy, that. Even CodeWarrior couldn't do that :-)
When this topic came up a few weeks ago Chris Espinosa said
>>>>> At this point there's too much diversity in configuration names and developers' existing macros for us to impose this on projects unilaterally. <<<<<
I really have to disagree. The Xcode team is letting the perfect be the enemy of the good. It would be good for the project templates to have DEBUG/RELEASE macros that matched the Debug/Release build configurations. That they can't be all things to all developers isn't a reason not to implement this. If there is a pre-defined macro then a developer can convert that #define into their own macro in the PCH file. This would be good. I don't see how having these macros pre-defined could cause a problem for anyone and they will solve a problem for most developers.
That this question comes up repeatedly on this list must mean something.
FWIW, CodeWarrior had these macros predefined in its project stationery and I never heard a complaint about it.
That's because a) they started that way and b) it was a homogenous community. With the diversity of sources of Mac OS X software (Classic, Carbon, Cocoa, BSD, etc.) we've researched several times the utility of imposing a predefined DEBUG macro on all projects, and have always come to the same conclusion:
- any macro common enough to be useful has the risk of breaking somebody's project with a conflict or by introducing unexpected behavior - any macro uncommon enough to be safe won't benefit anybody out of the box; people will generally have to define DEBUG=$(XCODE_DEBUG_CONFIGURATION) or some such.
At that point it's just as much work for everybody to define their own preferred debug macro in their own idiom, and more intuitive. In the future should we change the build system in a substantial way so that a change like this is in the noise, we definitely want to do something like this. If I could figure out how to fix this in the project templates for myself I would.
find /Developer/Library/Xcode/Project\ Templates/Application -name "project.pbxproj" -exec xed {} \;
For each file, search for "Build configuration list for PBXProject" (usually near the end of the file). Look for the line that says "/* Debug */" below that. Select the UUID next to it and do command-E-command-G; that takes you to its definition. In the build setting list, add
GCC_PREPROCESSOR_DEFINITIONS = "_DEBUG=1";
Save, repeat.
Chris |