Conditional compile #define for iOS and Android platform

I’m working on a cross platform library for iOS and Android devices. The header files for OpenGL ES are in different folders for these platforms (see end of post), so I need to #include them differently per platform. Took me a while to find the proper one to #define for the iOS platform, so here it is:

#ifdef __APPLE__
    #include "TargetConditionals.h"
#endif
 
#if (defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR))
    #define PLATFORM_IOS
#elif (defined(ANDROID))
    #define PLATFORM_ANDROID
#endif

TargetConditionals.h is where the Target_OS_IPHONE and TARGET_IPHONE_SIMULATOR are defined, and it is only available on a Mac, hence it is wrapped in __APPLE__. The second part, PLATFORM_IOS is the preprocessor macro I’ll use throughout my code.

The #elif clause takes care of Android platform.

The OpenGL ES headers are located here:

  • iOS
    • #include <OpenGLES/ES1/gl.h>
    • #include <OpenGLES/ES1/glext.h>
    • (Swap ES1 for ES2 if you’re using that)
  • Android
    • #include <GLES/gl.h>
    • #include <GLES/glext.h>
    • #include <GLES/glplatform.h>
    • #include <GLES2/gl2.h>
    • #include <GLES2/gl2ext.h>
    • #include <GLES2/gl2ext.h>

No Comments.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">