what defines are set up by xcode when compiling for iphone

what defines are set up by xcode when compiling for iphone  using -'ios,xcode,osx,conditional-compilation'

I'm writing some semi-portable code and want to be able to detect when I'm compiling for iPhone. So I want something like #ifdef IPHONE_SDK....

Presumably Xcode defines something, but I can't see anything under project properties, and Google isn't much help.

asked Oct 13, 2015 by deepak07.s
0 votes
1 view

2 Answers

0 votes

To look at all the defined macros, add this to the "Other C Flags" of your build config:

-g3 -save-temps -dD

You will get some build errors, but the compiler will dump all the defines into .mi files in your project's root directory. You can use grep to look at them, for example:

grep define main.mi

When you're done, don't forget to remove these options from the build setting.

answered Oct 13, 2015 by rajeevr642
0 votes

It's in the SDK docs under "Compiling source code conditionally"

The relevant definitions are TARGET_OS_IPHONE and TARGET_IPHONE_SIMULATOR, which are defined in /usr/include/TargetConditionals.h within the iOS framework. On earlier versions of the toolchain, you had to write:

#include "TargetConditionals.h"

but this is no longer necessary on the current (xCode 6/iOS8) toolchain.

So, for example, if you want to only compile a block of code if you are building for the device, then you should do

answered Oct 13, 2015 by virendra.bajaj