]> git.tdb.fi Git - builder.git/blob - source/vssolutiongenerator.cpp
43ed761cb52daa641388ad872596dacaa1ed30ce
[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         Builder &builder = target.get_package()->get_builder();
37
38         IO::BufferedFile out(target.get_path().str(), IO::M_WRITE);
39         IO::print(out, "Microsoft Visual Studio Solution File, Format Version 12.00\n");
40         IO::print(out, "MinimumVisualStudioVersion = 10.0.40219.1\n");
41
42         const Target::Dependencies &deps = target.get_dependencies();
43         vector<const VcxProjectFile *> projects;
44         for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
45                 if(const VcxProjectFile *project = dynamic_cast<const VcxProjectFile *>(*i))
46                         projects.push_back(project);
47
48         for(vector<const VcxProjectFile *>::const_iterator i=projects.begin(); i!=projects.end(); ++i)
49         {
50                 const SourcePackage *pkg = (*i)->get_package();
51                 IO::print(out, "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"%s\", \"%s\", \"{%s}\"\nEndProject\n",
52                         pkg->get_name(), (*i)->get_path(), (*i)->get_guid());
53         }
54
55         vector<string> build_types = builder.get_build_types();
56         const char *platforms[] = { "x86", "x64", 0 };
57
58         IO::print(out, "Global\n");
59         IO::print(out, "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n");
60         for(vector<string>::const_iterator i=build_types.begin(); i!=build_types.end(); ++i)
61                 for(const char **j=platforms; *j; ++j)
62                         IO::print(out, "\t\t%s|%s = %s|%s\n", *i, *j, *i, *j);
63         IO::print(out, "\tEndGlobalSection\n");
64         IO::print(out, "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n");
65         for(vector<const VcxProjectFile *>::const_iterator i=projects.begin(); i!=projects.end(); ++i)
66                 for(vector<string>::const_iterator j=build_types.begin(); j!=build_types.end(); ++j)
67                         for(const char **k=platforms; *k; ++k)
68                         {
69                                 const char *project_platform = (!strcmp(*k, "x86") ? "Win32" : *k);
70                                 IO::print(out, "\t\t{%s}.%s|%s.ActiveCfg = %s|%s\n", (*i)->get_guid(), *j, *k, *j, project_platform);
71                                 if(i==projects.begin())
72                                         IO::print(out, "\t\t{%s}.%s|%s.Build.0 = %s|%s\n", (*i)->get_guid(), *j, *k, *j, project_platform);
73                         }
74         IO::print(out, "\tEndGlobalSection\n");
75         IO::print(out, "EndGlobal\n");
76
77         status = Task::SUCCESS;
78 }