Xcconfig: various preprocessor macros for debugging / release

I created and applied a simple .xcconfig file containing

GCC_PREPROCESSOR_DEFINITIONS[config=Debug] = FOODEBUG
GCC_PREPROCESSOR_DEFINITIONS[config=Release] = FOORELEASE

and main.cpp containing

#include <iostream>

// This warning IS shown
#if DEBUG
#warning DEBUG is set to 1
#endif

// This warning IS NOT shown
#ifdef FOODEBUG
#warning FOODEBUG is set
#endif

// This warning IS NOT shown
#ifdef FOORELEASE
#warning FOORELEASE is set
#endif

int main(int argc, const char * argv[])
{
    // insert code here...
    std::cout << "Hello, World!\n";
    return 0;
}

Now I wonder why main.cpp does not define FOODEBUG or FOORELEASE ??!

As expected, the build options display two lines of my .xcconfig file ("Any architecture | Any SDK"), but they are not actually used.

Xcode screenshot

How could I achieve this?

+3
source share
1 answer

If you have a preprocessor macro, you need to give it a value in order to be able to use it just like you do, see a screenshot of one of my project settings as a sample:

enter image description here

, DEBUG, #if #ifdef. #if , , #ifdef, . , , , .

UPDATE:
, , config=Debug . , . 2 xcconfig, :

Release.xcconfig:

GCC_PREPROCESSOR_DEFINITIONS = $(inherited) FOORELEASE=1

Debug.xcconfig

#include "Release.xcconfig"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) FOODEBUG=1

. James Moores : xcconfig?

+2

All Articles