@@ -267,14 +267,14 @@ static String get_project_configuration(const SolutionSettings &s)
267267
268268static String get_vs_file_type_by_ext (const path &p)
269269{
270- String type = " ClCoNonempile " ;
270+ String type = " None " ;
271271 if (p.extension () == " .rc" )
272272 type = " ResourceCompile" ;
273273 else if (p.extension () == " .rule" )
274274 type = " CustomBuild" ;
275275 else if (isCppHeaderFileExtension (p.extension ().string ()))
276276 type = " ClInclude" ;
277- else if (isCppSourceFileExtensions (p.extension ().string ()))
277+ else if (isCppSourceFileExtensions (p.extension ().string ()) || p. extension () == " .c " )
278278 type = " ClCompile" ;
279279 return type;
280280}
@@ -504,6 +504,19 @@ void ProjectContext::printProject(
504504 addBlock (" Import" , " " , { { " Project" , " $(VCTargetsPath)\\ Microsoft.Cpp.props" } });
505505 addPropertySheets (b);
506506
507+ auto get_int_dir = [&dir, &projects_dir](auto &nt, auto &s)
508+ {
509+ auto tdir = dir / projects_dir;
510+ if (s.TargetOS .is (ArchType::x86_64))
511+ tdir /= " x64" ;
512+ return tdir / sha256_short (nt.pkg .toString ()) / sha256_short (get_project_configuration (s));
513+ };
514+
515+ StringSet filters; // dirs
516+ FiltersContext fctx;
517+ fctx.beginProject ();
518+ fctx.beginBlock (" ItemGroup" );
519+
507520 for (auto &s : b.solutions )
508521 {
509522 beginBlock (" PropertyGroup" , { { " Condition" , " '$(Configuration)|$(Platform)'=='" + get_project_configuration (s.Settings ) + " '" } });
@@ -582,12 +595,8 @@ void ProjectContext::printProject(
582595
583596 beginBlock (" PropertyGroup" , { { " Condition" , " '$(Configuration)|$(Platform)'=='" + get_project_configuration (s.Settings ) + " '" } });
584597 {
585- auto tdir = dir / projects_dir;
586- if (s.Settings .TargetOS .is (ArchType::x86_64))
587- tdir /= " x64" ;
588-
589598 // addBlock("OutDir", normalize_path_windows(current_thread_path() / "bin\\"));
590- addBlock (" IntDir" , normalize_path_windows (tdir / sha256_short (nt. pkg . toString () )) + " \\ " );
599+ addBlock (" IntDir" , normalize_path_windows (get_int_dir (nt, s. Settings )) + " \\ " );
591600 addBlock (" TargetName" , nt.pkg .toString ());
592601 // addBlock("TargetExt", ext);
593602 }
@@ -623,20 +632,39 @@ void ProjectContext::printProject(
623632 {
624633 beginBlock (" Link" );
625634 beginBlock (" AdditionalDependencies" , { { " Condition" , " '$(Configuration)|$(Platform)'=='" + get_project_configuration (s.Settings ) + " '" } });
626- for (auto &d : nt.Dependencies )
635+ std::set<void *> visited;
636+ std::function<void (NativeExecutedTarget&)> f;
637+ f = [&f, this , &dir, &s, &visited](auto &nt)
627638 {
628- if (d->isDummy ())
629- continue ;
639+ if (visited.find (&nt) != visited.end ())
640+ return ;
641+ visited.insert (&nt);
630642
631- deps.insert (d->target ->pkg .toString ());
643+ for (auto &d : nt.Dependencies )
644+ {
645+ if (d->isDummy ())
646+ continue ;
632647
633- auto tdir = dir;
634- if (s.Settings .TargetOS .is (ArchType::x86_64))
635- tdir /= " x64" ;
636- tdir /= get_configuration (s.Settings );
637- tdir /= d->target ->pkg .toString () + " .lib" ;
638- addText (normalize_path_windows (tdir) + " ;" );
639- }
648+ deps.insert (d->target ->pkg .toString ());
649+
650+ auto tdir = dir;
651+ if (s.Settings .TargetOS .is (ArchType::x86_64))
652+ tdir /= " x64" ;
653+ tdir /= get_configuration (s.Settings );
654+ tdir /= d->target ->pkg .toString () + " .lib" ;
655+ addText (normalize_path_windows (tdir) + " ;" );
656+
657+ if (s.Settings .Native .LibrariesType == LibraryType::Static)
658+ if (d->target ->getType () == TargetType::NativeLibrary || d->target ->getType () == TargetType::NativeStaticLibrary)
659+ {
660+ if (auto nt3 = d->target ->as <NativeExecutedTarget>())
661+ {
662+ f (*nt3);
663+ }
664+ }
665+ }
666+ };
667+ f (nt);
640668 addText (" %(AdditionalDependencies)" );
641669 endBlock (true );
642670 endBlock ();
@@ -645,11 +673,6 @@ void ProjectContext::printProject(
645673 endBlock ();
646674 }
647675
648- StringSet filters; // dirs
649- FiltersContext fctx;
650- fctx.beginProject ();
651- fctx.beginBlock (" ItemGroup" );
652-
653676 bool add_sources =
654677 ptype == VSProjectType::Utility ||
655678 g.type == GeneratorType::VisualStudio ||
@@ -666,22 +689,22 @@ void ProjectContext::printProject(
666689 File ff (p, *base_nt.getSolution ()->fs );
667690 if (g.type == GeneratorType::VisualStudio && ff.isGenerated ())
668691 {
669- auto gen = ff.getFileRecord ().getGenerator ();
670- if (rules.find (gen.get ()) == rules.end ())
692+ for (auto &s : b.solutions )
671693 {
672- rules.insert (gen.get ());
694+ File ff (p, *s.fs );
695+ auto gen = ff.getFileRecord ().getGenerator ();
696+ if (rules.find (gen.get ()) == rules.end ())
697+ {
698+ rules.insert (gen.get ());
673699
674- auto rule = dir / projects_dir / name / (p.filename ().string () + " .rule" );
675- if (!fs::exists (rule))
676- write_file (rule, " " );
700+ auto rule = get_int_dir (base_nt, s. Settings ) / " rules " / (p.filename ().string () + " .rule" );
701+ if (!fs::exists (rule))
702+ write_file (rule, " " );
677703
678- beginBlock (get_vs_file_type_by_ext (rule), { { " Include" , rule.string () } });
679- for (auto &s : b.solutions )
680- {
704+ beginBlock (get_vs_file_type_by_ext (rule), {{" Include" , rule.string ()}});
681705 String cmd;
682706
683- beginBlock (" AdditionalInputs" , { {
684- " Condition" , " '$(Configuration)|$(Platform)'=='" + get_project_configuration (s.Settings ) + " '" } });
707+ beginBlock (" AdditionalInputs" , {{" Condition" , " '$(Configuration)|$(Platform)'=='" + get_project_configuration (s.Settings ) + " '" }});
685708 // addText(normalize_path_windows(gen->program) + ";");
686709 if (auto dc = gen->as <driver::cpp::Command>())
687710 {
@@ -707,8 +730,7 @@ void ProjectContext::printProject(
707730 endBlock (true );
708731 for (auto &o : gen->outputs )
709732 {
710- beginBlock (" Outputs" , { {
711- " Condition" , " '$(Configuration)|$(Platform)'=='" + get_project_configuration (s.Settings ) + " '" } });
733+ beginBlock (" Outputs" , {{" Condition" , " '$(Configuration)|$(Platform)'=='" + get_project_configuration (s.Settings ) + " '" }});
712734 addText (normalize_path_windows (o) + " ;" );
713735 endBlock (true );
714736 }
@@ -723,28 +745,34 @@ void ProjectContext::printProject(
723745 if (!gen->err .file .empty ())
724746 cmd += " 2> \" " + normalize_path_windows (gen->err .file ) + " \" " ;
725747
726- beginBlock (" Command" , { {
727- " Condition" , " '$(Configuration)|$(Platform)'=='" + get_project_configuration (s.Settings ) + " '" } });
748+ beginBlock (" Command" , {{" Condition" , " '$(Configuration)|$(Platform)'=='" + get_project_configuration (s.Settings ) + " '" }});
728749 addText (cmd);
729750 endBlock (true );
730- }
731751
732- beginBlock (" Message" );
733- addText (gen->getName ());
734- endBlock (true );
752+ beginBlock (" Message" );
753+ addText (gen->getName ());
754+ endBlock (true );
735755
736- endBlock ();
756+ endBlock ();
757+
758+ auto filter = " . SW Rules" ;
759+ filters.insert (filter);
737760
738- auto filter = " . SW Rules" ;
739- filters.insert (filter);
761+ fctx.beginBlock (get_vs_file_type_by_ext (rule), {{" Include" , rule.string ()}});
762+ fctx.addBlock (" Filter" , make_backslashes (filter));
763+ fctx.endBlock ();
764+ }
740765
741- fctx. beginBlock (get_vs_file_type_by_ext (rule ), { {" Include" , rule .string ()} });
742- fctx. addBlock ( " Filter " , make_backslashes (filter) );
743- fctx. endBlock ();
766+ beginBlock (get_vs_file_type_by_ext (p ), { { " Include" , p .string () },
767+ { " Condition " , " '$(Configuration)|$(Platform)'==' " + get_project_configuration (s. Settings ) + " ' " } } );
768+ endBlock ();
744769 }
745770 }
746- beginBlock (get_vs_file_type_by_ext (p), { { " Include" , p.string () } });
747- endBlock ();
771+ else
772+ {
773+ beginBlock (get_vs_file_type_by_ext (p), { { " Include" , p.string () } });
774+ endBlock ();
775+ }
748776 }
749777 endBlock ();
750778 }
@@ -869,6 +897,10 @@ SolutionContext::Project &SolutionContext::addProject(VSProjectType type, const
869897 projects[n].name = n;
870898 projects[n].pctx .ptype = type;
871899 projects[n].solution_dir = solution_dir;
900+
901+ if (!solution_dir.empty ())
902+ nested_projects[n] = solution_dir;
903+
872904 return projects[n];
873905}
874906
@@ -1218,8 +1250,8 @@ void VSGenerator::generate(const Build &b)
12181250 auto pps = pp.toString ();
12191251 /* if (t->pkg.getOverriddenDir()) // uncomment for overridden
12201252 pps = overridden_deps_subdir / pps;
1221- else if (!t->Local)
1222- pps = deps_subdir / pps;*/
1253+ else */ if (!t->Local )
1254+ pps = deps_subdir / pps;
12231255
12241256 auto t2 = VSProjectType::Makefile;
12251257 if (type == GeneratorType::VisualStudio)
0 commit comments