Skip to content

Instantly share code, notes, and snippets.

@Ohmnivore
Last active October 29, 2018 20:20
Show Gist options
  • Save Ohmnivore/61897b4fc46170437776 to your computer and use it in GitHub Desktop.
Save Ohmnivore/61897b4fc46170437776 to your computer and use it in GitHub Desktop.
haxebullet helper cpp build file
package haxebullet;
import haxe.io.Path;
import haxe.macro.Context;
import haxe.macro.Expr;
import sys.FileSystem;
/**
* Add '@:build(haxebullet.MacroUtil.buildAll())' above your class Main {} declaration.
* buildAll accepts an argument, the path (relative to the current working directory when the build is called)
* to the directory containing the bullet cpp sources.
* @author Ohmnivore
*/
class MacroUtil {
static private function walkDir(Parent:String, HeaderFiles:Array<String>, CppFiles:Array<String>):Void {
var children:Array<String> = FileSystem.readDirectory(Parent);
for (child in children) {
var fullPath:String = Path.join([Parent, child]);
if (FileSystem.isDirectory(fullPath))
walkDir(fullPath, HeaderFiles, CppFiles);
else {
var ext:String = Path.extension(child);
if (ext == "h")
HeaderFiles.push(fullPath);
else if (ext == "cpp")
CppFiles.push(fullPath);
}
}
}
macro static public function buildAll(RootPath:String = "dependencies/bullet"):Array<Field> {
var fields:Array<Field> = Context.getBuildFields();
var localClass = Context.getLocalClass();
var headerFiles:Array<String> = [];
var cppFiles:Array<String> = [];
walkDir(RootPath, headerFiles, cppFiles);
var cwd:String = Sys.getCwd();
var includeStr:String = "<compilerflag value='-I" + Path.join([cwd, RootPath]) + "'/>";
var buildStr:String = "";
buildStr += "<files id='haxe'>" + includeStr;
for (c in cppFiles)
buildStr += "<file name='" + Path.join([cwd, c]) + "'/>";
buildStr += "</files>";
buildStr += "<files id='__lib__'>" + includeStr;
for (c in cppFiles)
buildStr += "<file name='" + Path.join([cwd, c]) + "'/>";
buildStr += "</files>";
localClass.get().meta.add(":buildXml", [macro $v{buildStr}], Context.currentPos());
return fields;
}
}
@KurtLHayes
Copy link

Having trouble trying to follow this example to get haxe bullet C++ target to build. I have been able to get html5 target to build and run. Looking at this code, are the headerFiles that get populated when walking the directory on line 38 supposed to be added to the buildStr below along with the cppFiles?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment