Search code examples
haxeconditional-compilation

Haxe: Are there defines indicating the current compilation target?


Does Haxe have any defines indicating the current compilation target, which can be used for conditional compilation?


Solution

  • Yes, every Haxe target has it's own define.

    #if js 
      trace("js");
    #elseif php
      trace("php");
    #elseif cpp
      trace("cpp");
    #elseif java
      trace("java");
    #elseif python
      trace("python");
    #elseif neko
      trace("neko");
    #elseif sys
      trace("sys");
    #elseif flash
      trace("flash");
    #elseif cs
      trace("cs");
    #elseif macro
      trace("macro");
    #end
    

    You can find more build-in compilation flags here:
    http://haxe.org/manual/lf-condition-compilation-flags.html

    More info about conditional compilation:
    http://haxe.org/manual/lf-condition-compilation.html