Răsfoiți Sursa

Merge topic 'fbuild_proj_deps'

b9f2b6c40b FASTBuild: specify VS proj deps

Acked-by: Kitware Robot <[email protected]>
Merge-request: !11556
Brad King 1 zi în urmă
părinte
comite
6e87a412ce

+ 7 - 1
Source/cmFastbuildNormalTargetGenerator.cxx

@@ -857,6 +857,12 @@ void cmFastbuildNormalTargetGenerator::Generate()
   this->GeneratorTarget->CheckCxxModuleStatus(Config);
 
   FastbuildTarget fastbuildTarget;
+  auto const addUtilDepToTarget = [&fastbuildTarget](std::string depName) {
+    FastbuildTargetDep dep{ depName };
+    dep.Type = FastbuildTargetDepType::UTIL;
+    fastbuildTarget.PreBuildDependencies.emplace(std::move(dep));
+  };
+
   fastbuildTarget.Name = GetTargetName();
   fastbuildTarget.BaseName = this->GeneratorTarget->GetName();
 
@@ -882,7 +888,7 @@ void cmFastbuildNormalTargetGenerator::Generate()
 
   for (auto& cc : GenerateCommands(FastbuildBuildStep::PRE_BUILD).Nodes) {
     fastbuildTarget.PreBuildExecNodes.PreBuildDependencies.emplace(cc.Name);
-    fastbuildTarget.PreBuildDependencies.emplace(cc.Name);
+    addUtilDepToTarget(cc.Name);
     this->GetGlobalGenerator()->AddTarget(std::move(cc));
   }
   for (auto& cc : GenerateCommands(FastbuildBuildStep::PRE_LINK).Nodes) {

+ 19 - 7
Source/cmFastbuildUtilityTargetGenerator.cxx

@@ -35,7 +35,14 @@ void cmFastbuildUtilityTargetGenerator::Generate()
   }
 
   FastbuildAliasNode fastbuildTarget;
+  auto const addUtilDepToTarget = [&fastbuildTarget](std::string depName) {
+    FastbuildTargetDep dep{ depName };
+    dep.Type = FastbuildTargetDepType::UTIL;
+    fastbuildTarget.PreBuildDependencies.emplace(std::move(dep));
+  };
+
   fastbuildTarget.Name = targetName;
+  fastbuildTarget.BaseName = targetName;
 
   LogMessage("<-------------->");
   LogMessage("Generate Utility target: " + targetName);
@@ -67,12 +74,11 @@ void cmFastbuildUtilityTargetGenerator::Generate()
         LogMessage("Transitively propagating iface dep: " + depName +
                    ", is cross: " + std::to_string(dep.Value.second));
         nonImportedUtils.emplace_back(depName);
-        fastbuildTarget.PreBuildDependencies.emplace(
-          this->ConvertToFastbuildPath(depName));
+        addUtilDepToTarget(this->ConvertToFastbuildPath(depName));
       }
     } else {
       nonImportedUtils.emplace_back(utilTargetName);
-      fastbuildTarget.PreBuildDependencies.emplace(utilTargetName);
+      addUtilDepToTarget(utilTargetName);
     }
   }
   if (this->GetGlobalGenerator()->IsExcluded(this->GetGeneratorTarget())) {
@@ -84,7 +90,7 @@ void cmFastbuildUtilityTargetGenerator::Generate()
   // Tested in "RunCMake.CPack*" tests.
   // Utility target "package" has packaging steps as "POST_BUILD".
   for (auto& exec : GenerateCommands(FastbuildBuildStep::POST_BUILD).Nodes) {
-    fastbuildTarget.PreBuildDependencies.emplace(exec.Name);
+    addUtilDepToTarget(exec.Name);
     for (std::string const& util : nonImportedUtils) {
       LogMessage("Adding: util " + util);
       exec.PreBuildDependencies.emplace(util);
@@ -100,12 +106,12 @@ void cmFastbuildUtilityTargetGenerator::Generate()
 
   for (auto& exec : preBuild.Nodes) {
     LogMessage("Adding exec " + exec.Name);
-    fastbuildTarget.PreBuildDependencies.emplace(exec.Name);
+    addUtilDepToTarget(exec.Name);
     this->GetGlobalGenerator()->AddTarget(std::move(exec));
   }
 
   for (auto& exec : GenerateCommands(FastbuildBuildStep::REST).Nodes) {
-    fastbuildTarget.PreBuildDependencies.emplace(exec.Name);
+    addUtilDepToTarget(exec.Name);
     for (auto const& dep : TargetDirectDependencies) {
       LogMessage("Direct dep " + dep->GetName() +
                  "-all propagating to CC: " + exec.Name);
@@ -119,9 +125,15 @@ void cmFastbuildUtilityTargetGenerator::Generate()
     if (fastbuildTarget.ExcludeFromAll) {
       return;
     }
-    fastbuildTarget.PreBuildDependencies.emplace(FASTBUILD_NOOP_FILE_NAME);
+    FastbuildTargetDep dep{ FASTBUILD_NOOP_FILE_NAME };
+    dep.Type = FastbuildTargetDepType::ORDER_ONLY;
+    fastbuildTarget.PreBuildDependencies.emplace(std::move(dep));
   }
   fastbuildTarget.Hidden = false;
   this->AdditionalCleanFiles();
+
+  fastbuildTarget.BasePath = this->GetMakefile()->GetCurrentSourceDirectory();
+  this->GetGlobalGenerator()->AddIDEProject(fastbuildTarget, Config);
+
   this->GetGlobalGenerator()->AddTarget(std::move(fastbuildTarget));
 }

+ 42 - 6
Source/cmGlobalFastbuildGenerator.cxx

@@ -51,6 +51,7 @@
 // IDE support
 #define FASTBUILD_XCODE_BASE_PATH "XCode/Projects"
 #define FASTBUILD_VS_BASE_PATH "VisualStudio/Projects"
+#define FASTBUILD_VS_PROJECT_SUFFIX "-vcxproj"
 
 #define FASTBUILD_IDE_VS_COMMAND_PREFIX "cd ^$(SolutionDir).. && "
 #define FASTBUILD_DEFAULT_IDE_BUILD_ARGS " -ide -cache -summary -dist "
@@ -1613,12 +1614,23 @@ void cmGlobalFastbuildGenerator::AddGlobCheckExec()
 void cmGlobalFastbuildGenerator::WriteSolution()
 {
   std::string const solutionName = LocalGenerators[0]->GetProjectName();
-  std::map<std::string /*folder*/, std::vector<std::string>> VSProjects;
+  std::unordered_map<std::string /*folder*/, std::vector<std::string>>
+    VSProjectFolders;
+  std::unordered_map<std::string /*project*/,
+                     std::vector<std::string> /*deps*/>
+    VSProjectDeps;
   std::vector<std::string> VSProjectsWithoutFolder;
 
   for (auto const& IDEProj : IDEProjects) {
     auto const VSProj = IDEProj.second.first;
-    VSProjects[VSProj.folder].emplace_back(VSProj.Alias);
+    VSProjectFolders[VSProj.folder].emplace_back(VSProj.Alias);
+    auto& deps = VSProjectDeps[VSProj.Alias];
+    deps.reserve(VSProj.deps.size());
+    for (auto const& dep : VSProj.deps) {
+      if (dep.Type == FastbuildTargetDepType::REGULAR) {
+        deps.push_back(cmStrCat(dep.Name, FASTBUILD_VS_PROJECT_SUFFIX));
+      }
+    }
   }
 
   WriteCommand("VSSolution", Quote("solution"));
@@ -1632,7 +1644,7 @@ void cmGlobalFastbuildGenerator::WriteSolution()
   WriteIDEProjectConfig(configs, "SolutionConfigs");
   int folderNumber = 0;
   std::vector<std::string> folders;
-  for (auto& item : VSProjects) {
+  for (auto& item : VSProjectFolders) {
     auto const& pathToFolder = item.first;
     auto& projectsInFolder = item.second;
     if (pathToFolder.empty()) {
@@ -1652,6 +1664,29 @@ void cmGlobalFastbuildGenerator::WriteSolution()
   if (!folders.empty()) {
     WriteArray("SolutionFolders ", Wrap(folders, ".", ""), 1);
   }
+
+  int depNumber = 0;
+  std::vector<std::string> dependencies;
+  for (auto const& dep : VSProjectDeps) {
+    std::string const& projectName = dep.first;
+    std::vector<std::string> const& projectDeps = dep.second;
+    // This project has some deps.
+    if (!projectDeps.empty()) {
+      std::string depName = cmStrCat("Deps_", ++depNumber);
+      WriteStruct(depName,
+                  {
+                    { "Projects", Quote(projectName) },
+                    { "Dependencies",
+                      cmStrCat('{', cmJoin(Wrap(projectDeps), ","), '}') },
+                  },
+                  1);
+      dependencies.emplace_back(std::move(depName));
+    }
+  }
+
+  if (!dependencies.empty()) {
+    WriteArray("SolutionDependencies  ", Wrap(dependencies, ".", ""), 1);
+  }
   if (!VSProjectsWithoutFolder.empty()) {
     WriteArray("SolutionProjects", Wrap(VSProjectsWithoutFolder), 1);
   }
@@ -1872,8 +1907,8 @@ cmGlobalFastbuildGenerator::GetTargetByOutputName(
   return cm::nullopt;
 }
 
-void cmGlobalFastbuildGenerator::AddIDEProject(FastbuildTarget const& target,
-                                               std::string const& config)
+void cmGlobalFastbuildGenerator::AddIDEProject(
+  FastbuildTargetBase const& target, std::string const& config)
 {
   auto const& configs = GetConfigNames();
   if (std::find(configs.begin(), configs.end(), config) == configs.end()) {
@@ -1886,11 +1921,12 @@ void cmGlobalFastbuildGenerator::AddIDEProject(FastbuildTarget const& target,
     this->GetCMakeInstance()->GetHomeDirectory(), target.BasePath);
   // VS
   auto& VSProject = IDEProject.first;
-  VSProject.Alias = target.BaseName + "-vcxproj";
+  VSProject.Alias = cmStrCat(target.BaseName, FASTBUILD_VS_PROJECT_SUFFIX);
   VSProject.ProjectOutput = cmStrCat("VisualStudio/Projects/", relativeSubdir,
                                      '/', target.BaseName + ".vcxproj");
   VSProject.ProjectBasePath = target.BasePath;
   VSProject.folder = relativeSubdir;
+  VSProject.deps = target.PreBuildDependencies;
   // XCode
   auto& XCodeProject = IDEProject.second;
   XCodeProject.Alias = target.BaseName + "-xcodeproj";

+ 5 - 1
Source/cmGlobalFastbuildGenerator.h

@@ -96,6 +96,8 @@ enum class FastbuildTargetDepType
   ORDER_ONLY,
   // Regular target dep.
   REGULAR,
+  // Utility target dep.
+  UTIL,
 };
 struct FastbuildTargetDep
 {
@@ -265,6 +267,7 @@ struct XCodeProject : public IDEProjectCommon
 struct VCXProject : public IDEProjectCommon
 {
   std::string folder;
+  std::set<FastbuildTargetDep> deps;
 };
 
 struct FastbuildLinkerNode
@@ -545,7 +548,8 @@ public:
   void AddCompiler(std::string const& lang, cmMakefile* mf);
   void AddLauncher(std::string const& prefix, std::string const& launcher,
                    std::string const& lang, std::string const& args);
-  void AddIDEProject(FastbuildTarget const& target, std::string const& config);
+  void AddIDEProject(FastbuildTargetBase const& target,
+                     std::string const& config);
 
   template <class T>
   void AddTarget(T target)