Skip to content
Robert Konrad edited this page Sep 24, 2020 · 8 revisions

System defines help us write platform specific code while still using one code-base for all targets.

To get a target language, regular #if js/cpp/cs/... will work

To get a target platform, use #if kha_windows/kha_html5/kha_ios/...

The HTML5 and Android targets exist for two different target languages. If necessary you can combine the language and platform defines to differentiate the targets. There's also always a define equivalent to your khamake call - for example when you call node Kha/make android-native to use the C++ based Android target cpp, kha_android, and kha_android_native will be defined.

If using more than one define at a time, you can use the || and && operators like so:

  • #if (kha_android || kha_ios)
  • #if (kha_html5 && js)

You can also string them together using #elseif like so:

#if (kha_android || kha_ios)
///do some code for iOS/Android
#elseif kha_html5
///do some code for html5
#end

To see if graphics4 or audio2 apis are supported, use #if kha_g4/kha_a2

Clone this wiki locally