12.6.3.9 Xml Injection

When using external code in hxcpp, it is often useful to add libraries, include paths or compiler flags to the build process. This can be done with the @:buildXml class metadata. E.g.:

@:buildXml("
<target id='haxe'>
  <lib name='${haxelib:nme}/lib/${BINDIR}/libnme${LIBEXTRA}${LIBEXT}'/>
</target>
")
@:keep
class StaticNme { ... }

By referencing the given class (by simply import-ing it, no need to use it properly because it has the @:keep metadata), the XML fragment is also included.

Here, the XML fragment is copied verbatim into the generated Build.xml immediately after the standard file lists. This example adds a library to the haxe target, but you could also add flags to files nodes, or files to another files node or target. Another possibility is to add an include command to pull in a whole external XML file. This can help avoid some syntax awkwardness needed when quoting strings in metadata, and allows a normal XML editor to be used.

It is also possible to replace the __main__ file group to skip the standard initialization code and use a custom bootstrap procedure.