Home > Back-end >  Xcode: preprocessor macros from configurations not seen in editor
Xcode: preprocessor macros from configurations not seen in editor

Time:09-08

Xcode seems to "build" for the editor warnings and errors with a configuration, which differs from the current scheme and thus does not pick up the preprocessor macros, which I define in xcconfig files.

I use a Standard.xcconfig files in which I define a preprocessor macro like this:

GCC_PREPROCESSOR_DEFINITIONS = $(inherited) X_MY_FLAG=1

I added new configurations "Debug Standard" and "Release Standard" in which I select the Standard configuration for the project (or the target).

I added a new scheme, which uses the "... Standard" variants of the configurations and select it in that dropdown in the top line of Xcode.

In main.m I use this snippet to test for the macro:

#if X_MY_FLAG == 1
#warning "Success. X_MY_FLAG picked up."
#else
#error "X_MY_FLAG not picked up"
#endif

Running a build (Cmd-B) produces a nice build output and as expected the warning message appears, not the error. However, in the editor window I also get the error information shown. (See screenshot below.) Seeing both cases of the #if getting evaluated is not what I want to see here.

enter image description here

So for the editor Xcode runs a "build", which does not use the configuration specified in the selected scheme. Does anybody have a hint, how to fix this or what the actual underlying problem is?

CodePudding user response:

Xcode editor seems to always evaluate macro expressions for some "default" configuration in the Configurations list. As a result, if you have your Configuration Set file specified for any other configuration, it's not what editor window reflects (in this case Debug is the configuration editor parses preprocessor for):

enter image description here

It's silly but it seems you cannot alter this "default" configuration for the editor window, and what it does under the hood is simply sorting them with an unknown criterion.

I assume Xcode just takes Debug configuration when it's available or sort the list in alphabetical order and takes the first one from the sorted list of configurations otherwise, so renaming Debug to Webug for example, makes it a least preferred candidate for the macro evaluating by the editor window:

enter image description here

  • Related