]> git.tdb.fi Git - builder.git/blob - source/vssolutiongenerator.cpp
Replace basic for loops with range-based loops or algorithms
[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 "sourcepackage.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
17 Target *VsSolutionGenerator::create_target(const list<Target *> &, const string &)
18 {
19         throw logic_error("Not implemented");
20 }
21
22 Task *VsSolutionGenerator::run(const Target &target) const
23 {
24         const VsSolutionFile &solution = dynamic_cast<const VsSolutionFile &>(target);
25         Worker *worker = new Worker(solution);
26         return new InternalTask(worker);
27 }
28
29
30 VsSolutionGenerator::Worker::Worker(const VsSolutionFile &t):
31         target(t)
32 { }
33
34 void VsSolutionGenerator::Worker::main()
35 {
36         const SourcePackage &spkg = *target.get_package();
37         Builder &builder = spkg.get_builder();
38
39         IO::BufferedFile out(target.get_path().str(), IO::M_WRITE);
40         IO::print(out, "Microsoft Visual Studio Solution File, Format Version 12.00\n");
41         IO::print(out, "MinimumVisualStudioVersion = 10.0.40219.1\n");
42
43         vector<const VcxProjectFile *> projects;
44         for(const Target *t: target.get_dependencies())
45                 if(const VcxProjectFile *project = dynamic_cast<const VcxProjectFile *>(t))
46                         projects.push_back(project);
47
48         for(const VcxProjectFile *p: projects)
49         {
50                 const SourcePackage *pkg = p->get_package();
51                 IO::print(out, "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"%s\", \"%s\", \"{%s}\"\nEndProject\n",
52                         pkg->get_name(), p->get_path(), p->get_guid());
53         }
54
55         vector<string> build_types = builder.get_build_types();
56         const char *platforms[] = { "x86", "x64" };
57
58         IO::print(out, "Global\n");
59         IO::print(out, "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n");
60         for(const string &t: build_types)
61                 for(const char *p: platforms)
62                         IO::print(out, "\t\t%s|%s = %s|%s\n", t, p, t, p);
63         IO::print(out, "\tEndGlobalSection\n");
64         IO::print(out, "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n");
65         for(const VcxProjectFile *p: projects)
66                 for(const string &t: build_types)
67                         for(const char *f: platforms)
68                         {
69                                 const char *project_platform = (!strcmp(f, "x86") ? "Win32" : f);
70                                 IO::print(out, "\t\t{%s}.%s|%s.ActiveCfg = %s|%s\n", p->get_guid(), t, f, t, project_platform);
71                                 if(p->get_package()==&spkg)
72                                         IO::print(out, "\t\t{%s}.%s|%s.Build.0 = %s|%s\n", p->get_guid(), t, f, t, project_platform);
73                         }
74         IO::print(out, "\tEndGlobalSection\n");
75         IO::print(out, "EndGlobal\n");
76
77         status = Task::SUCCESS;
78 }