XCode Preprocessor Macro for Configuration?
Asked Answered
C

1

7

I want my XCode Objective-C project to be able to detect which configuration it is being built with. How can I achieve this?

Cobol answered 28/9, 2009 at 3:42 Comment(0)
M
14

You can have per-configuration macro definitions. Open up your project settings, select your configuration from the Configuration drop-down menu, and go to Preprocessor Macros. For Debug, I recommend defining the macro _DEBUG, and for release I recommend defining _RELEASE, as these are the typical ones which are used. These are passed on to the compiler as -D options, e.g. -D_DEBUG.

You can also put -D options directly into the Other C Flags setting.

Mayflower answered 28/9, 2009 at 3:49 Comment(3)
Can I define them under "User-Defined" because I don't see "Preprocessor Macros" unless you mean "Info.plist other preprocessor flags"?Cobol
It seems that if I selected "Base SDK" the options would then appear.Cobol
@Adam - _DEBUG and _RELEASE are OK, but non-standard. Posix only observes NDEBUG, so the Release configuration should definitely include it. To cover all the bases (including interop'ing with other libraries, such as SQLite and SQLCipher), and including your macros: Debug configurations should have the following preprocessor macros: _DEBUG, DEBUG=1; and Release configuration should have _RELEASE, NDEBUG=1, NS_BLOCK_ASSERTIONS=1 preprocessor macros.Humoresque

© 2022 - 2024 — McMap. All rights reserved.