]> git.tdb.fi Git - builder.git/commitdiff
Emit configurations in Visual Studio solutions
authorMikko Rasa <tdb@tdb.fi>
Sun, 18 Dec 2022 18:02:17 +0000 (20:02 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 19 Dec 2022 00:06:49 +0000 (02:06 +0200)
Projects other than the main one are marked as not being built, since
builder will build them implicitly as part of the main project.

This also seems to be enough for Visual Studio to not complain about the
solution being modified when closing it.

source/vssolutiongenerator.cpp

index 90adc693ebdedd7a51b0cffb41929343aac792be..43ed761cb52daa641388ad872596dacaa1ed30ce 100644 (file)
@@ -1,5 +1,7 @@
+#include <cstring>
 #include <msp/io/file.h>
 #include <msp/io/print.h>
+#include "builder.h"
 #include "sourcepackage.h"
 #include "vcxprojectfile.h"
 #include "vssolutionfile.h"
@@ -31,18 +33,46 @@ VsSolutionGenerator::Worker::Worker(const VsSolutionFile &t):
 
 void VsSolutionGenerator::Worker::main()
 {
+       Builder &builder = target.get_package()->get_builder();
+
        IO::BufferedFile out(target.get_path().str(), IO::M_WRITE);
        IO::print(out, "Microsoft Visual Studio Solution File, Format Version 12.00\n");
        IO::print(out, "MinimumVisualStudioVersion = 10.0.40219.1\n");
 
        const Target::Dependencies &deps = target.get_dependencies();
+       vector<const VcxProjectFile *> projects;
        for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
                if(const VcxProjectFile *project = dynamic_cast<const VcxProjectFile *>(*i))
-               {
-                       const SourcePackage *pkg = project->get_package();
-                       IO::print(out, "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"%s\", \"%s\", \"{%s}\"\nEndProject\n",
-                               pkg->get_name(), project->get_path(), project->get_guid());
-               }
+                       projects.push_back(project);
+
+       for(vector<const VcxProjectFile *>::const_iterator i=projects.begin(); i!=projects.end(); ++i)
+       {
+               const SourcePackage *pkg = (*i)->get_package();
+               IO::print(out, "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"%s\", \"%s\", \"{%s}\"\nEndProject\n",
+                       pkg->get_name(), (*i)->get_path(), (*i)->get_guid());
+       }
+
+       vector<string> build_types = builder.get_build_types();
+       const char *platforms[] = { "x86", "x64", 0 };
+
+       IO::print(out, "Global\n");
+       IO::print(out, "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n");
+       for(vector<string>::const_iterator i=build_types.begin(); i!=build_types.end(); ++i)
+               for(const char **j=platforms; *j; ++j)
+                       IO::print(out, "\t\t%s|%s = %s|%s\n", *i, *j, *i, *j);
+       IO::print(out, "\tEndGlobalSection\n");
+       IO::print(out, "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n");
+       for(vector<const VcxProjectFile *>::const_iterator i=projects.begin(); i!=projects.end(); ++i)
+               for(vector<string>::const_iterator j=build_types.begin(); j!=build_types.end(); ++j)
+                       for(const char **k=platforms; *k; ++k)
+                       {
+                               const char *project_platform = (!strcmp(*k, "x86") ? "Win32" : *k);
+                               IO::print(out, "\t\t{%s}.%s|%s.ActiveCfg = %s|%s\n", (*i)->get_guid(), *j, *k, *j, project_platform);
+                               if(i==projects.begin())
+                                       IO::print(out, "\t\t{%s}.%s|%s.Build.0 = %s|%s\n", (*i)->get_guid(), *j, *k, *j, project_platform);
+                       }
+       IO::print(out, "\tEndGlobalSection\n");
+       IO::print(out, "EndGlobal\n");
 
        status = Task::SUCCESS;
 }