2 #include <msp/io/file.h>
3 #include <msp/io/print.h>
5 #include "internaltask.h"
6 #include "sourcepackage.h"
7 #include "vcxprojectfile.h"
8 #include "vssolutionfile.h"
9 #include "vssolutiongenerator.h"
14 Target *VsSolutionGenerator::create_target(const vector<Target *> &, const string &)
16 throw logic_error("Not implemented");
19 Task *VsSolutionGenerator::run(const Target &target) const
21 const VsSolutionFile &solution = dynamic_cast<const VsSolutionFile &>(target);
22 return new InternalTask([&solution]{ return _run(solution); });
25 bool VsSolutionGenerator::_run(const VsSolutionFile &solution)
27 const SourcePackage &spkg = *solution.get_package();
28 Builder &builder = spkg.get_builder();
30 IO::BufferedFile out(solution.get_path().str(), IO::M_WRITE);
31 IO::print(out, "Microsoft Visual Studio Solution File, Format Version 12.00\n");
32 IO::print(out, "MinimumVisualStudioVersion = 10.0.40219.1\n");
34 vector<const VcxProjectFile *> projects;
35 for(const Target *t: solution.get_dependencies())
36 if(const VcxProjectFile *project = dynamic_cast<const VcxProjectFile *>(t))
37 projects.push_back(project);
39 for(const VcxProjectFile *p: projects)
41 const SourcePackage *pkg = p->get_package();
42 IO::print(out, "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"%s\", \"%s\", \"{%s}\"\nEndProject\n",
43 pkg->get_name(), p->get_path(), p->get_guid());
46 vector<string> build_types = builder.get_build_types();
47 const char *platforms[] = { "x86", "x64" };
49 IO::print(out, "Global\n");
50 IO::print(out, "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n");
51 for(const string &t: build_types)
52 for(const char *p: platforms)
53 IO::print(out, "\t\t%s|%s = %s|%s\n", t, p, t, p);
54 IO::print(out, "\tEndGlobalSection\n");
55 IO::print(out, "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n");
56 for(const VcxProjectFile *p: projects)
57 for(const string &t: build_types)
58 for(const char *f: platforms)
60 const char *project_platform = (!strcmp(f, "x86") ? "Win32" : f);
61 IO::print(out, "\t\t{%s}.%s|%s.ActiveCfg = %s|%s\n", p->get_guid(), t, f, t, project_platform);
62 if(p->get_package()==&spkg)
63 IO::print(out, "\t\t{%s}.%s|%s.Build.0 = %s|%s\n", p->get_guid(), t, f, t, project_platform);
65 IO::print(out, "\tEndGlobalSection\n");
66 IO::print(out, "EndGlobal\n");