Jinja2 fixes

I tested it against builds that stress out the cmake generation pretty well, so think it's good with these fixes.