3

I'm writing a library that I need to run on Windows, Mac, Linux, Android, iOS. I have the following definitions already:

#if defined(_WIN32) || defined(__WIN32__)

    // Windows
    #define SYSTEM_WINDOWS

#elif defined(linux) || defined(__linux)

    // Linux
    #define SYSTEM_LINUX

#elif defined(__APPLE__) || defined(MACOSX) || defined(macintosh) || defined(Macintosh)

    // MacOS
    #define SYSTEM_MACOS

#elif defined(__ANDROID__)

    // Android
    #define SYSTEM_ANDROID

#else

    // Unsupported system
    #error This operating system is not supported

#endif

But I'm not sure what to use for iOS.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • 1
    see [this SO thread](http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor) – LorenzoDonati4Ukraine-OnStrike Sep 07 '13 at 17:42
  • So TARGET_OS_IPHONE is used for any iOS device? Seems a bit too unambiguous. –  Sep 07 '13 at 17:50
  • Here's a more detailed description. http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system#OSXiOSandDarwin. Also [this SO question](http://stackoverflow.com/questions/7836967/how-to-define-preprocessor-macro-to-check-ios-version) discusses how to differentiate versions. – Wandering Logic Sep 07 '13 at 17:52
  • @Mike You don't seem to mind that `__ANDROID__` is used for **any** Android device either. How is that any different? – IInspectable Sep 07 '13 at 17:54
  • The iPhone is not an operating system. If the only way to detect Android was with __GALAXY_TAB__ I would question the logic in that as well. Thanks Wandering Logic, that's a great link. –  Sep 07 '13 at 17:59
  • @Mike The iPhone was the first device to run on iOS, hence the name of the preprocessor macro. Once shipped, you cannot change the SDK headers. Unless you go back in time, but there are no reports of successful time travel to date. – IInspectable Sep 07 '13 at 18:04
  • Because once you have multiple devices running the OS you can't simply add a new macro. It's not like they make new versions of the SDK in which the old macro could be deprecated over time while a new once becomes prominent. It doesn't matter anyways, it just seems odd to me. Besides, the iPhone and iPod Touch were released within months of each other. They had to know the OS would be used on other devices. –  Sep 07 '13 at 18:29
  • @Mike There is no correlation between the release date of a product and the date work on a product starts. – IInspectable Sep 08 '13 at 11:51

1 Answers1

0

In /usr/include/TargetConditionals.h, you can find the definition for TARGET_OS_IPHONE, which will have a value of 1 for both iOS and the iOS simulator.

Please see the following link to determine how to detect the OS for multiple platforms:

Detecting the OS Using Predefined Macros