--- /dev/null
+#include <msp/core/application.h>
+#include <msp/fs/utils.h>
+#include <msp/io/print.h>
+#include <msp/strings/utils.h>
+#include "builder.h"
+#include "csourcefile.h"
+#include "executable.h"
+#include "sourcepackage.h"
+#include "vcxprojectfile.h"
+#include "vcxprojectgenerator.h"
+
+using namespace std;
+using namespace Msp;
+
+VcxProjectGenerator::VcxProjectGenerator(Builder &b):
+ Tool(b, "VCXG")
+{ }
+
+Target *VcxProjectGenerator::create_target(const list<Target *> &, const string &)
+{
+ throw logic_error("Not implemented");
+}
+
+Task *VcxProjectGenerator::run(const Target &target) const
+{
+ const VcxProjectFile &project = dynamic_cast<const VcxProjectFile &>(target);
+ Worker *worker = new Worker(project);
+ return new InternalTask(worker);
+}
+
+
+VcxProjectGenerator::Worker::Worker(const VcxProjectFile &t):
+ target(t)
+{ }
+
+void VcxProjectGenerator::Worker::main()
+{
+ const SourcePackage &spkg = *target.get_package();
+ Builder &builder = spkg.get_builder();
+
+ IO::BufferedFile out(target.get_path().str(), IO::M_WRITE);
+ IO::print(out, "<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n");
+
+ IO::print(out, "\t<ItemGroup Label=\"ProjectConfigurations\">\n");
+ vector<string> build_types = builder.get_build_types();
+ const char *platforms[] = { "x86-32", "x86-64", 0 };
+ for(const char **i=platforms; *i; ++i)
+ for(vector<string>::const_iterator j=build_types.begin(); j!=build_types.end(); ++j)
+ {
+ IO::print(out, "\t\t<ProjectConfiguration Include=\"%s|%s\">\n", *j, *i);
+ IO::print(out, "\t\t\t<Configuration>%s</Configuration>\n", *j);
+ IO::print(out, "\t\t\t<Platform>%s</Platform>\n", *i);
+ IO::print(out, "\t\t</ProjectConfiguration>\n");
+ }
+ IO::print(out, "\t</ItemGroup>\n");
+
+ IO::print(out, "\t<PropertyGroup Label=\"Globals\">\n");
+ IO::print(out, "\t\t<VCProjectVersion>15.0</VCProjectVersion>\n");
+ IO::print(out, "\t\t<Keyword>MakeFileProj</Keyword>\n");
+ IO::print(out, "\t</PropertyGroup>\n");
+
+ IO::print(out, "\t<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n");
+
+ const Target *world = builder.get_build_graph().get_target("world");
+ const Target::Dependencies &world_deps = world->get_dependencies();
+ const Executable *exe = 0;
+ for(Target::Dependencies::const_iterator i=world_deps.begin(); (!exe && i!=world_deps.end()); ++i)
+ if((*i)->get_package()==&spkg)
+ exe = dynamic_cast<const Executable *>(*i);
+
+ const char *argv0 = Application::get_argv0();
+ for(const char **i=platforms; *i; ++i)
+ for(vector<string>::const_iterator j=build_types.begin(); j!=build_types.end(); ++j)
+ {
+ IO::print(out, "\t<PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='%s|%s'\" Label=\"Configuration\">\n", *j, *i);
+ IO::print(out, "\t\t<ConfigurationType>MakeFile</ConfigurationType>\n");
+ IO::print(out, "\t\t<NMakeBuildCommandLine>%s --arch=%s --build-type=%s</NMakeBuildCommandLine>\n", argv0, *i, *j);
+ IO::print(out, "\t\t<NMakeCleanCommandLine>%s --arch=%s --build-type=%s -c</NMakeCleanCommandLine>\n", argv0, *i, *j);
+ IO::print(out, "\t\t<NMakeReBuildCommandLine>%s --arch=%s --build-type=%s -B</NMakeReBuildCommandLine>\n", argv0, *i, *j);
+ if(exe)
+ IO::print(out, "\t\t<NMakeOutput>%s</NMakeOutput>\n", exe->get_path());
+ IO::print(out, "\t</PropertyGroup>\n");
+ }
+
+ IO::print(out, "\t<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n");
+
+ const BuildGraph::TargetMap &targets = builder.get_build_graph().get_targets();
+ vector<const FileTarget *> sources;
+ vector<const FileTarget *> includes;
+ vector<const FileTarget *> others;
+ for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
+ if(i->second->get_package()==&spkg && !i->second->is_buildable())
+ if(const FileTarget *file = dynamic_cast<const FileTarget *>(i->second))
+ {
+ if(dynamic_cast<const CSourceFile *>(file))
+ {
+ string ext = tolower(FS::extpart(FS::basename(file->get_path())));
+ if(ext==".h" || ext==".hpp")
+ includes.push_back(file);
+ else
+ sources.push_back(file);
+ }
+ else
+ others.push_back(file);
+ }
+
+ IO::print(out, "\t<ItemGroup>\n");
+ for(vector<const FileTarget *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
+ IO::print(out, "\t\t<ClCompile Include=\"%s\" />\n", (*i)->get_path());
+ IO::print(out, "\t</ItemGroup>\n");
+
+ IO::print(out, "\t<ItemGroup>\n");
+ for(vector<const FileTarget *>::const_iterator i=includes.begin(); i!=includes.end(); ++i)
+ IO::print(out, "\t\t<ClInclude Include=\"%s\" />\n", (*i)->get_path());
+ IO::print(out, "\t</ItemGroup>\n");
+
+ IO::print(out, "\t<ItemGroup>\n");
+ for(vector<const FileTarget *>::const_iterator i=others.begin(); i!=others.end(); ++i)
+ IO::print(out, "\t\t<None Include=\"%s\" />\n", (*i)->get_path());
+ IO::print(out, "\t</ItemGroup>\n");
+
+ IO::print(out, "\t<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n");
+ IO::print(out, "</Project>\n");
+
+ status = Task::SUCCESS;
+}