Is it possible to set a symbol for conditional compilation by setting up properties in an Xcode project?
My aim is to to create a symbol that is available to all files, without having to use import/include, so that a set of common classes can have a special behavior in some projects. Like the following, but with my own symbols.
#if TARGET_IPHONE_SIMULATOR
...
#endif
This question is related to
objective-c
xcode
c-preprocessor
You don't need to create a user-defined setting. The built-in setting "Preprocessor Macros" works just fine. alt text http://idisk.mac.com/cdespinosa/Public/Picture%204.png
If you have multiple targets or projects that use the same prefix file, use Preprocessor Macros Not Used In Precompiled Headers instead, so differences in your macro definition don't trigger an unnecessary extra set of precompiled headers.
You don't need to create a user-defined setting. The built-in setting "Preprocessor Macros" works just fine. alt text http://idisk.mac.com/cdespinosa/Public/Picture%204.png
If you have multiple targets or projects that use the same prefix file, use Preprocessor Macros Not Used In Precompiled Headers instead, so differences in your macro definition don't trigger an unnecessary extra set of precompiled headers.
It's under "GCC 4.2 Preprocessing" (or just put "prepro" in the search box)...
...however, for the life of me I can't get it to work.
I have my standard Debug and Release configurations, and I want to define DEBUG=1 in the debugging configuration. But after adding it as a value:
(in the settings window) > Preprocessor Macros : DEBUG=1
#if DEBUG
printf("DEBUG is set!");
#endif
...never prints/gets called. It's driving me crazy...
You can use the *_Prefix.pch
file to declare project wide macros.
That file is usually in you Other Sources group.
You don't need to create a user-defined setting. The built-in setting "Preprocessor Macros" works just fine. alt text http://idisk.mac.com/cdespinosa/Public/Picture%204.png
If you have multiple targets or projects that use the same prefix file, use Preprocessor Macros Not Used In Precompiled Headers instead, so differences in your macro definition don't trigger an unnecessary extra set of precompiled headers.
You can duplicate the target which has the preprocessing section, rename it to any name you want, and then change your Preprocessor macro value.
It's under "GCC 4.2 Preprocessing" (or just put "prepro" in the search box)...
...however, for the life of me I can't get it to work.
I have my standard Debug and Release configurations, and I want to define DEBUG=1 in the debugging configuration. But after adding it as a value:
(in the settings window) > Preprocessor Macros : DEBUG=1
#if DEBUG
printf("DEBUG is set!");
#endif
...never prints/gets called. It's driving me crazy...
You can use the *_Prefix.pch
file to declare project wide macros.
That file is usually in you Other Sources group.
For Xcode 9.4.1 and C++ project. Adding const char*
Preprocessor Macros to both Debug and Release builds.
Select your project
Select Build Settings
Search "Preprocessor Macros"
Open interactive list
Add your macros and don't forget to escape quotation
Use in source code as common const char*
...
#ifndef JSON_DEFINITIONS_FILE_PATH
static constexpr auto JSON_DEFINITIONS_FILE_PATH = "definitions.json";
#endif
...
FILE *pFileIn = fopen(JSON_DEFINITIONS_FILE_PATH, "r");
...
In response to Kevin Laity's comment (see cdespinosa's answer), about the GCC Preprocessing section not showing in your build settings, make the Active SDK the one that says (Base SDK) after it and this section will appear. You can do this by choosing the menu Project > Set Active Target > XXX (Base SDK). In different versions of XCode (Base SDK) maybe different, like (Project Setting or Project Default).
After you get this section appears, you can add your definitions to Processor Macros rather than creating a user-defined setting.
You don't need to create a user-defined setting. The built-in setting "Preprocessor Macros" works just fine. alt text http://idisk.mac.com/cdespinosa/Public/Picture%204.png
If you have multiple targets or projects that use the same prefix file, use Preprocessor Macros Not Used In Precompiled Headers instead, so differences in your macro definition don't trigger an unnecessary extra set of precompiled headers.
As an addendum, if you are using this technique to define strings in your target, this is how I had to define and use them:
In Build Settings -> Preprocessor Macros, and yes backslashes are critical in the definition:
APPURL_NSString=\@\"www.foobar.org\"
And in the source code:
objectManager.client.baseURL = APPURL_NSString;
For Xcode 9.4.1 and C++ project. Adding const char*
Preprocessor Macros to both Debug and Release builds.
Select your project
Select Build Settings
Search "Preprocessor Macros"
Open interactive list
Add your macros and don't forget to escape quotation
Use in source code as common const char*
...
#ifndef JSON_DEFINITIONS_FILE_PATH
static constexpr auto JSON_DEFINITIONS_FILE_PATH = "definitions.json";
#endif
...
FILE *pFileIn = fopen(JSON_DEFINITIONS_FILE_PATH, "r");
...
As an addendum, if you are using this technique to define strings in your target, this is how I had to define and use them:
In Build Settings -> Preprocessor Macros, and yes backslashes are critical in the definition:
APPURL_NSString=\@\"www.foobar.org\"
And in the source code:
objectManager.client.baseURL = APPURL_NSString;
In response to Kevin Laity's comment (see cdespinosa's answer), about the GCC Preprocessing section not showing in your build settings, make the Active SDK the one that says (Base SDK) after it and this section will appear. You can do this by choosing the menu Project > Set Active Target > XXX (Base SDK). In different versions of XCode (Base SDK) maybe different, like (Project Setting or Project Default).
After you get this section appears, you can add your definitions to Processor Macros rather than creating a user-defined setting.
Source: Stackoverflow.com