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