1 #include "gamesetupgenerator.h"
2 #include <msp/builder/builder.h>
3 #include <msp/fs/utils.h>
4 #include "gamesetupdefinitions.h"
9 GameSetupGenerator::GameSetupGenerator(Builder &b):
12 input_suffixes.push_back(".mgs");
14 set_command("mspgame-setupgen");
15 set_run_external(_run);
18 Target *GameSetupGenerator::create_source(const Component &comp, const FS::Path &path) const
20 return new GameSetupDefinitions(builder, comp, path);
23 Target *GameSetupGenerator::create_target(const vector<Target *> &sources, const string &)
26 throw invalid_argument("GameSetupGenerator::create_target");
28 GameSetupDefinitions &defs = dynamic_cast<GameSetupDefinitions &>(*sources.front());
30 const Component &comp = *defs.get_component();
31 const SourcePackage &spkg = comp.get_package();
32 FS::Path dir = spkg.get_temp_directory()/"generated";
33 dir /= FS::dirname(FS::relative(defs.get_path(), spkg.get_source_directory()));
35 Tool &compiler = builder.get_toolchain().get_tool("CC");
36 string base = FS::basepart(FS::basename(defs.get_path()));
37 Target *source = compiler.create_source(comp, dir/(base+".cpp"));
38 source->add_dependency(defs);
39 source->set_tool(*this);
41 Target *header = compiler.create_source(comp, dir/(base+".h"));
42 header->add_dependency(defs);
43 source->add_side_effect(*header);
48 ExternalTask::Arguments GameSetupGenerator::_run(const CSourceFile &out_src, FS::Path &work_dir)
50 const Tool &tool = *out_src.get_tool();
52 ExternalTask::Arguments argv;
53 argv.push_back(tool.get_executable()->get_path().str());
56 out_src.collect_build_info(binfo);
58 for(const FS::Path &i: binfo.incpath)
59 argv.push_back("-I"+i.str());
61 for(const Target *d: out_src.get_dependencies())
62 if(const GameSetupDefinitions *defs = dynamic_cast<const GameSetupDefinitions *>(d))
63 argv.push_back(FS::relative(defs->get_path(), work_dir).str());
66 argv.push_back(FS::relative(out_src.get_path(), work_dir).str());