瀏覽代碼

cmGlobalVisualStudioGenerator: Adopt more solution generation methods

Brad King 1 月之前
父節點
當前提交
6b1c101410

+ 0 - 71
Source/cmGlobalVisualStudio7Generator.cxx

@@ -57,14 +57,6 @@ static cmVS7FlagTable cmVS7ExtraFlagTable[] = {
   { "", "", "", "", 0 }
 };
 
-namespace {
-std::string GetSLNFile(cmLocalGenerator* root)
-{
-  return cmStrCat(root->GetCurrentBinaryDirectory(), '/',
-                  root->GetProjectName(), ".sln");
-}
-}
-
 cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator(cmake* cm)
   : cmGlobalVisualStudioGenerator(cm)
 {
@@ -293,69 +285,6 @@ bool cmGlobalVisualStudio7Generator::SetSystemName(std::string const& s,
   return this->cmGlobalVisualStudioGenerator::SetSystemName(s, mf);
 }
 
-void cmGlobalVisualStudio7Generator::Generate()
-{
-  // first do the superclass method
-  this->cmGlobalVisualStudioGenerator::Generate();
-
-  // Now write out the VS Solution files.
-  for (auto& it : this->ProjectMap) {
-    this->OutputSLNFile(it.second[0], it.second);
-  }
-
-  // If any solution or project files changed during the generation,
-  // tell Visual Studio to reload them...
-  if (!cmSystemTools::GetErrorOccurredFlag() &&
-      !this->LocalGenerators.empty()) {
-    this->CallVisualStudioMacro(MacroReload,
-                                GetSLNFile(this->LocalGenerators[0].get()));
-  }
-
-  if (this->Version == VSVersion::VS14 &&
-      !this->CMakeInstance->GetIsInTryCompile()) {
-    std::string cmakeWarnVS14;
-    if (cmValue cached = this->CMakeInstance->GetState()->GetCacheEntryValue(
-          "CMAKE_WARN_VS14")) {
-      this->CMakeInstance->MarkCliAsUsed("CMAKE_WARN_VS14");
-      cmakeWarnVS14 = *cached;
-    } else {
-      cmSystemTools::GetEnv("CMAKE_WARN_VS14", cmakeWarnVS14);
-    }
-    if (cmakeWarnVS14.empty() || !cmIsOff(cmakeWarnVS14)) {
-      this->CMakeInstance->IssueMessage(
-        MessageType::WARNING,
-        "The \"Visual Studio 14 2015\" generator is deprecated "
-        "and will be removed in a future version of CMake."
-        "\n"
-        "Add CMAKE_WARN_VS14=OFF to the cache to disable this warning.");
-    }
-  }
-}
-
-void cmGlobalVisualStudio7Generator::OutputSLNFile(
-  cmLocalGenerator* root, std::vector<cmLocalGenerator*>& generators)
-{
-  if (generators.empty()) {
-    return;
-  }
-
-  // Collect all targets under this root generator and the transitive
-  // closure of their dependencies.
-  TargetDependSet const projectTargets =
-    this->GetTargetsForProject(root, generators);
-
-  std::string fname = GetSLNFile(root);
-  cmGeneratedFileStream fout(fname);
-  fout.SetCopyIfDifferent(true);
-  if (!fout) {
-    return;
-  }
-  this->WriteSLNFile(fout, root, projectTargets);
-  if (fout.Close()) {
-    this->FileReplacedDuringGenerate(fname);
-  }
-}
-
 void cmGlobalVisualStudio7Generator::AppendDirectoryForConfig(
   std::string const& prefix, std::string const& config,
   std::string const& suffix, std::string& dir)

+ 0 - 5
Source/cmGlobalVisualStudio7Generator.h

@@ -118,16 +118,11 @@ public:
 protected:
   cmGlobalVisualStudio7Generator(cmake* cm);
 
-  void Generate() override;
-
   std::string const& GetDevEnvCommand();
   virtual std::string FindDevEnvCommand();
 
   static char const* ExternalProjectType(std::string const& location);
 
-  virtual void OutputSLNFile(cmLocalGenerator* root,
-                             std::vector<cmLocalGenerator*>& generators);
-
   bool MarmasmEnabled;
   bool MasmEnabled;
   bool NasmEnabled;

+ 71 - 0
Source/cmGlobalVisualStudioGenerator.cxx

@@ -38,6 +38,14 @@
 #include "cmUuid.h"
 #include "cmake.h"
 
+namespace {
+std::string GetSLNFile(cmLocalGenerator* root)
+{
+  return cmStrCat(root->GetCurrentBinaryDirectory(), '/',
+                  root->GetProjectName(), ".sln");
+}
+}
+
 cmGlobalVisualStudioGenerator::cmGlobalVisualStudioGenerator(cmake* cm)
   : cmGlobalGenerator(cm)
 {
@@ -1084,6 +1092,69 @@ cm::VS::Solution cmGlobalVisualStudioGenerator::CreateSolution(
   return solution;
 }
 
+void cmGlobalVisualStudioGenerator::Generate()
+{
+  // first do the superclass method
+  this->cmGlobalGenerator::Generate();
+
+  // Now write out the VS Solution files.
+  for (auto& it : this->ProjectMap) {
+    this->OutputSLNFile(it.second[0], it.second);
+  }
+
+  // If any solution or project files changed during the generation,
+  // tell Visual Studio to reload them...
+  if (!cmSystemTools::GetErrorOccurredFlag() &&
+      !this->LocalGenerators.empty()) {
+    this->CallVisualStudioMacro(MacroReload,
+                                GetSLNFile(this->LocalGenerators[0].get()));
+  }
+
+  if (this->Version == VSVersion::VS14 &&
+      !this->CMakeInstance->GetIsInTryCompile()) {
+    std::string cmakeWarnVS14;
+    if (cmValue cached = this->CMakeInstance->GetState()->GetCacheEntryValue(
+          "CMAKE_WARN_VS14")) {
+      this->CMakeInstance->MarkCliAsUsed("CMAKE_WARN_VS14");
+      cmakeWarnVS14 = *cached;
+    } else {
+      cmSystemTools::GetEnv("CMAKE_WARN_VS14", cmakeWarnVS14);
+    }
+    if (cmakeWarnVS14.empty() || !cmIsOff(cmakeWarnVS14)) {
+      this->CMakeInstance->IssueMessage(
+        MessageType::WARNING,
+        "The \"Visual Studio 14 2015\" generator is deprecated "
+        "and will be removed in a future version of CMake."
+        "\n"
+        "Add CMAKE_WARN_VS14=OFF to the cache to disable this warning.");
+    }
+  }
+}
+
+void cmGlobalVisualStudioGenerator::OutputSLNFile(
+  cmLocalGenerator* root, std::vector<cmLocalGenerator*>& generators)
+{
+  if (generators.empty()) {
+    return;
+  }
+
+  // Collect all targets under this root generator and the transitive
+  // closure of their dependencies.
+  TargetDependSet const projectTargets =
+    this->GetTargetsForProject(root, generators);
+
+  std::string fname = GetSLNFile(root);
+  cmGeneratedFileStream fout(fname);
+  fout.SetCopyIfDifferent(true);
+  if (!fout) {
+    return;
+  }
+  this->WriteSLNFile(fout, root, projectTargets);
+  if (fout.Close()) {
+    this->FileReplacedDuringGenerate(fname);
+  }
+}
+
 void cmGlobalVisualStudioGenerator::WriteSLNFile(
   std::ostream& fout, cmLocalGenerator* root,
   TargetDependSet const& projectTargets) const

+ 5 - 0
Source/cmGlobalVisualStudioGenerator.h

@@ -196,6 +196,11 @@ protected:
   cm::VS::Solution::Folder* CreateSolutionFolder(
     cm::VS::Solution& solution, cm::string_view rawName) const;
 
+  void Generate() override;
+
+  void OutputSLNFile(cmLocalGenerator* root,
+                     std::vector<cmLocalGenerator*>& generators);
+
   void WriteSLNFile(std::ostream& fout, cmLocalGenerator* root,
                     TargetDependSet const& projectTargets) const;