]> git.tdb.fi Git - builder.git/blob - plugins/msvc/vssolutiongenerator.cpp
Move the VS project and solution generators to the MSVC plugin
[builder.git] / plugins / msvc / vssolutiongenerator.cpp
1 #include <cstring>
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"
9
10 using namespace std;
11 using namespace Msp;
12
13 VsSolutionGenerator::VsSolutionGenerator(Builder &b):
14         Tool(b, "VSSG")
15 {
16         set_run_internal(_run);
17 }
18
19 Target *VsSolutionGenerator::create_target(const vector<Target *> &, const string &)
20 {
21         throw logic_error("Not implemented");
22 }
23
24 bool VsSolutionGenerator::_run(const VsSolutionFile &solution)
25 {
26         const SourcePackage &spkg = *solution.get_package();
27         Builder &builder = spkg.get_builder();
28
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");
32
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);
37
38         for(const VcxProjectFile *p: projects)
39         {
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());
43         }
44
45         vector<string> build_types = builder.get_build_types();
46         const char *platforms[] = { "x86", "x64" };
47
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)
58                         {
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);
63                         }
64         IO::print(out, "\tEndGlobalSection\n");
65         IO::print(out, "EndGlobal\n");
66
67         return true;
68 }