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