]> git.tdb.fi Git - builder.git/blob - source/vssolutiongenerator.cpp
Redesign how tools are run
[builder.git] / source / vssolutiongenerator.cpp
1 #include <cstring>
2 #include <msp/io/file.h>
3 #include <msp/io/print.h>
4 #include "builder.h"
5 #include "internaltask.h"
6 #include "sourcepackage.h"
7 #include "vcxprojectfile.h"
8 #include "vssolutionfile.h"
9 #include "vssolutiongenerator.h"
10
11 using namespace std;
12 using namespace Msp;
13
14 VsSolutionGenerator::VsSolutionGenerator(Builder &b):
15         Tool(b, "VSSG")
16 {
17         set_run_internal(_run);
18 }
19
20 Target *VsSolutionGenerator::create_target(const vector<Target *> &, const string &)
21 {
22         throw logic_error("Not implemented");
23 }
24
25 bool VsSolutionGenerator::_run(const VsSolutionFile &solution)
26 {
27         const SourcePackage &spkg = *solution.get_package();
28         Builder &builder = spkg.get_builder();
29
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");
33
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);
38
39         for(const VcxProjectFile *p: projects)
40         {
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());
44         }
45
46         vector<string> build_types = builder.get_build_types();
47         const char *platforms[] = { "x86", "x64" };
48
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)
59                         {
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);
64                         }
65         IO::print(out, "\tEndGlobalSection\n");
66         IO::print(out, "EndGlobal\n");
67
68         return true;
69 }