Преглед изворни кода

Merge topic 'vs-show-cmake-files'

df58dbb0e9 VS: Add CMake input files to ZERO_CHECK
659e9ae937 cmGlobalVisualStudio8Generator: Collect CMake input files earlier

Acked-by: Kitware Robot <[email protected]>
Merge-request: !8260
Brad King пре 2 година
родитељ
комит
2fbcc81440

+ 27 - 12
Source/cmGlobalVisualStudio8Generator.cxx

@@ -262,6 +262,33 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
   cmTarget* tgt = lg.AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false,
   cmTarget* tgt = lg.AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false,
                                        std::move(cc));
                                        std::move(cc));
 
 
+  // Collect the input files used to generate all targets in this
+  // project.
+  std::vector<std::string> listFiles;
+  for (const auto& gen : generators) {
+    cm::append(listFiles, gen->GetMakefile()->GetListFiles());
+  }
+  // Sort the list of input files and remove duplicates.
+  std::sort(listFiles.begin(), listFiles.end(), std::less<std::string>());
+  auto new_end = std::unique(listFiles.begin(), listFiles.end());
+  listFiles.erase(new_end, listFiles.end());
+
+  // Add all cmake input files which are used by the project
+  // so Visual Studio does not close them when reloading it.
+  for (const std::string& listFile : listFiles) {
+    if (listFile.find("/CMakeFiles/") != std::string::npos) {
+      continue;
+    }
+    if (!cmSystemTools::IsSubDirectory(listFile,
+                                       lg.GetMakefile()->GetHomeDirectory()) &&
+        !cmSystemTools::IsSubDirectory(
+          listFile, lg.GetMakefile()->GetHomeOutputDirectory())) {
+      continue;
+    }
+
+    tgt->AddSource(listFile);
+  }
+
   auto ptr = cm::make_unique<cmGeneratorTarget>(tgt, &lg);
   auto ptr = cm::make_unique<cmGeneratorTarget>(tgt, &lg);
   auto* gt = ptr.get();
   auto* gt = ptr.get();
   lg.AddGeneratorTarget(std::move(ptr));
   lg.AddGeneratorTarget(std::move(ptr));
@@ -295,13 +322,6 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
     // The custom rule runs cmake so set UTF-8 pipes.
     // The custom rule runs cmake so set UTF-8 pipes.
     bool stdPipesUTF8 = true;
     bool stdPipesUTF8 = true;
 
 
-    // Collect the input files used to generate all targets in this
-    // project.
-    std::vector<std::string> listFiles;
-    for (const auto& gen : generators) {
-      cm::append(listFiles, gen->GetMakefile()->GetListFiles());
-    }
-
     // Add a custom prebuild target to run the VerifyGlobs script.
     // Add a custom prebuild target to run the VerifyGlobs script.
     cmake* cm = this->GetCMakeInstance();
     cmake* cm = this->GetCMakeInstance();
     if (cm->DoWriteGlobVerifyTarget()) {
     if (cm->DoWriteGlobVerifyTarget()) {
@@ -325,11 +345,6 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
       listFiles.push_back(cm->GetGlobVerifyStamp());
       listFiles.push_back(cm->GetGlobVerifyStamp());
     }
     }
 
 
-    // Sort the list of input files and remove duplicates.
-    std::sort(listFiles.begin(), listFiles.end(), std::less<std::string>());
-    auto new_end = std::unique(listFiles.begin(), listFiles.end());
-    listFiles.erase(new_end, listFiles.end());
-
     // Create a rule to re-run CMake.
     // Create a rule to re-run CMake.
     std::string argS = cmStrCat("-S", lg.GetSourceDirectory());
     std::string argS = cmStrCat("-S", lg.GetSourceDirectory());
     std::string argB = cmStrCat("-B", lg.GetBinaryDirectory());
     std::string argB = cmStrCat("-B", lg.GetBinaryDirectory());

+ 55 - 1
Source/cmVisualStudio10TargetGenerator.cxx

@@ -9,6 +9,7 @@
 #include <set>
 #include <set>
 #include <sstream>
 #include <sstream>
 
 
+#include <cm/filesystem>
 #include <cm/memory>
 #include <cm/memory>
 #include <cm/optional>
 #include <cm/optional>
 #include <cm/string_view>
 #include <cm/string_view>
@@ -51,6 +52,8 @@
 #include "cmValue.h"
 #include "cmValue.h"
 #include "cmVisualStudioGeneratorOptions.h"
 #include "cmVisualStudioGeneratorOptions.h"
 
 
+const std::string kBuildSystemSources = "Buildsystem Input Files";
+
 struct cmIDEFlagTable;
 struct cmIDEFlagTable;
 
 
 static void ConvertToWindowsSlash(std::string& s);
 static void ConvertToWindowsSlash(std::string& s);
@@ -1950,7 +1953,13 @@ void cmVisualStudio10TargetGenerator::WriteGroups()
                  "http://schemas.microsoft.com/developer/msbuild/2003");
                  "http://schemas.microsoft.com/developer/msbuild/2003");
 
 
     for (auto const& ti : this->Tools) {
     for (auto const& ti : this->Tools) {
-      this->WriteGroupSources(e0, ti.first, ti.second, sourceGroups);
+      if ((this->GeneratorTarget->GetName() ==
+           CMAKE_CHECK_BUILD_SYSTEM_TARGET) &&
+          (ti.first == "None")) {
+        this->WriteBuildSystemSources(e0, ti.first, ti.second);
+      } else {
+        this->WriteGroupSources(e0, ti.first, ti.second, sourceGroups);
+      }
     }
     }
 
 
     // Added files are images and the manifest.
     // Added files are images and the manifest.
@@ -2021,6 +2030,18 @@ void cmVisualStudio10TargetGenerator::WriteGroups()
                    "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;"
                    "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;"
                    "gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms");
                    "gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms");
       }
       }
+
+      if (this->GeneratorTarget->GetName() ==
+          CMAKE_CHECK_BUILD_SYSTEM_TARGET) {
+        for (const std::string& filter : this->BuildSystemSourcesFilters) {
+          std::string guidName = "SG_Filter_";
+          guidName += filter;
+          std::string guid = this->GlobalGenerator->GetGUID(guidName);
+          Elem e2(e1, "Filter");
+          e2.Attribute("Include", filter);
+          e2.Element("UniqueIdentifier", "{" + guid + "}");
+        }
+      }
     }
     }
   }
   }
   fout << '\n';
   fout << '\n';
@@ -2087,6 +2108,39 @@ void cmVisualStudio10TargetGenerator::WriteGroupSources(
   }
   }
 }
 }
 
 
+void cmVisualStudio10TargetGenerator::WriteBuildSystemSources(
+  Elem& e0, std::string const& name, ToolSources const& sources)
+{
+  const std::string srcDir = this->Makefile->GetCurrentSourceDirectory();
+  const std::string::size_type srcDirLength = srcDir.length();
+
+  Elem e1(e0, "ItemGroup");
+  e1.SetHasElements();
+  for (ToolSource const& s : sources) {
+    cmSourceFile const* sf = s.SourceFile;
+    std::string const& source = sf->GetFullPath();
+
+    cm::filesystem::path sourcePath(source);
+    bool isInSrcDir = cmHasPrefix(source, srcDir);
+
+    std::string filter = kBuildSystemSources;
+    if (isInSrcDir) {
+      std::string parentPath = sourcePath.parent_path().string();
+      if (srcDir != parentPath) {
+        filter += parentPath.substr(srcDirLength);
+      }
+      ConvertToWindowsSlash(filter);
+      this->BuildSystemSourcesFilters.insert(filter);
+    }
+
+    std::string path = this->ConvertPath(source, s.RelativePath);
+    ConvertToWindowsSlash(path);
+    Elem e2(e1, name);
+    e2.Attribute("Include", path);
+    e2.Element("Filter", filter);
+  }
+}
+
 void cmVisualStudio10TargetGenerator::WriteHeaderSource(
 void cmVisualStudio10TargetGenerator::WriteHeaderSource(
   Elem& e1, cmSourceFile const* sf, ConfigToSettings const& toolSettings)
   Elem& e1, cmSourceFile const* sf, ConfigToSettings const& toolSettings)
 {
 {

+ 4 - 0
Source/cmVisualStudio10TargetGenerator.h

@@ -193,6 +193,9 @@ private:
   void WriteGroupSources(Elem& e0, std::string const& name,
   void WriteGroupSources(Elem& e0, std::string const& name,
                          ToolSources const& sources,
                          ToolSources const& sources,
                          std::vector<cmSourceGroup>&);
                          std::vector<cmSourceGroup>&);
+  void WriteBuildSystemSources(Elem& e0, std::string const& name,
+                               ToolSources const& sources);
+
   void AddMissingSourceGroups(std::set<cmSourceGroup const*>& groupsUsed,
   void AddMissingSourceGroups(std::set<cmSourceGroup const*>& groupsUsed,
                               const std::vector<cmSourceGroup>& allGroups);
                               const std::vector<cmSourceGroup>& allGroups);
   bool IsResxHeader(const std::string& headerFile);
   bool IsResxHeader(const std::string& headerFile);
@@ -243,6 +246,7 @@ private:
   std::set<std::string> ASanEnabledConfigurations;
   std::set<std::string> ASanEnabledConfigurations;
   std::set<std::string> FuzzerEnabledConfigurations;
   std::set<std::string> FuzzerEnabledConfigurations;
   std::map<std::string, std::string> SpectreMitigation;
   std::map<std::string, std::string> SpectreMitigation;
+  std::set<std::string> BuildSystemSourcesFilters;
   cmGlobalVisualStudio10Generator* const GlobalGenerator;
   cmGlobalVisualStudio10Generator* const GlobalGenerator;
   cmLocalVisualStudio10Generator* const LocalGenerator;
   cmLocalVisualStudio10Generator* const LocalGenerator;
   std::set<std::string> CSharpCustomCommandNames;
   std::set<std::string> CSharpCustomCommandNames;

+ 214 - 0
Tests/RunCMake/FileAPI/codemodel-v2-check.py

@@ -848,7 +848,203 @@ def gen_check_targets(c, g, inSource):
         for e in expected:
         for e in expected:
             if e["type"] == "UTILITY":
             if e["type"] == "UTILITY":
                 if e["id"] == "^ZERO_CHECK::@6890427a1f51a3e7e1df$":
                 if e["id"] == "^ZERO_CHECK::@6890427a1f51a3e7e1df$":
+                    # The json files have data for Xcode.  Substitute data for VS.
                     e["sources"] = [
                     e["sources"] = [
+                        {
+                            "path": "^CMakeLists\\.txt$",
+                            "isGenerated": None,
+                            "fileSetName": None,
+                            "sourceGroupName": "",
+                            "compileGroupLanguage": None,
+                            "backtrace": [
+                                {
+                                    "file": "^CMakeLists\\.txt$",
+                                    "line": None,
+                                    "command": None,
+                                    "hasParent": False,
+                                },
+                            ],
+                        },
+                        {
+                            "path": "^alias/CMakeLists\\.txt$",
+                            "isGenerated": None,
+                            "fileSetName": None,
+                            "sourceGroupName": "",
+                            "compileGroupLanguage": None,
+                            "backtrace": [
+                                {
+                                    "file": "^CMakeLists\\.txt$",
+                                    "line": None,
+                                    "command": None,
+                                    "hasParent": False,
+                                },
+                            ],
+                        },
+                        {
+                            "path": "^codemodel-v2\\.cmake$",
+                            "isGenerated": None,
+                            "fileSetName": None,
+                            "sourceGroupName": "",
+                            "compileGroupLanguage": None,
+                            "backtrace": [
+                                {
+                                    "file": "^CMakeLists\\.txt$",
+                                    "line": None,
+                                    "command": None,
+                                    "hasParent": False,
+                                },
+                            ],
+                        },
+                        {
+                            "path": "^custom/CMakeLists\\.txt$",
+                            "isGenerated": None,
+                            "fileSetName": None,
+                            "sourceGroupName": "",
+                            "compileGroupLanguage": None,
+                            "backtrace": [
+                                {
+                                    "file": "^CMakeLists\\.txt$",
+                                    "line": None,
+                                    "command": None,
+                                    "hasParent": False,
+                                },
+                            ],
+                        },
+                        {
+                            "path": "^cxx/CMakeLists\\.txt$",
+                            "isGenerated": None,
+                            "fileSetName": None,
+                            "sourceGroupName": "",
+                            "compileGroupLanguage": None,
+                            "backtrace": [
+                                {
+                                    "file": "^CMakeLists\\.txt$",
+                                    "line": None,
+                                    "command": None,
+                                    "hasParent": False,
+                                },
+                            ],
+                        },
+                        {
+                            "path": "^dir/CMakeLists\\.txt$",
+                            "isGenerated": None,
+                            "fileSetName": None,
+                            "sourceGroupName": "",
+                            "compileGroupLanguage": None,
+                            "backtrace": [
+                                {
+                                    "file": "^CMakeLists\\.txt$",
+                                    "line": None,
+                                    "command": None,
+                                    "hasParent": False,
+                                },
+                            ],
+                        },
+                        {
+                            "path": "^dir/dir/CMakeLists\\.txt$",
+                            "isGenerated": None,
+                            "fileSetName": None,
+                            "sourceGroupName": "",
+                            "compileGroupLanguage": None,
+                            "backtrace": [
+                                {
+                                    "file": "^CMakeLists\\.txt$",
+                                    "line": None,
+                                    "command": None,
+                                    "hasParent": False,
+                                },
+                            ],
+                        },
+                        {
+                            "path": "^fileset/CMakeLists\\.txt$",
+                            "isGenerated": None,
+                            "fileSetName": None,
+                            "sourceGroupName": "",
+                            "compileGroupLanguage": None,
+                            "backtrace": [
+                                {
+                                    "file": "^CMakeLists\\.txt$",
+                                    "line": None,
+                                    "command": None,
+                                    "hasParent": False,
+                                },
+                            ],
+                        },
+                        {
+                            "path": "^imported/CMakeLists\\.txt$",
+                            "isGenerated": None,
+                            "fileSetName": None,
+                            "sourceGroupName": "",
+                            "compileGroupLanguage": None,
+                            "backtrace": [
+                                {
+                                    "file": "^CMakeLists\\.txt$",
+                                    "line": None,
+                                    "command": None,
+                                    "hasParent": False,
+                                },
+                            ],
+                        },
+                        {
+                            "path": "^include_test\\.cmake$",
+                            "isGenerated": None,
+                            "fileSetName": None,
+                            "sourceGroupName": "",
+                            "compileGroupLanguage": None,
+                            "backtrace": [
+                                {
+                                    "file": "^CMakeLists\\.txt$",
+                                    "line": None,
+                                    "command": None,
+                                    "hasParent": False,
+                                },
+                            ],
+                        },
+                        {
+                            "path": "^interface/CMakeLists\\.txt$",
+                            "isGenerated": None,
+                            "fileSetName": None,
+                            "sourceGroupName": "",
+                            "compileGroupLanguage": None,
+                            "backtrace": [
+                                {
+                                    "file": "^CMakeLists\\.txt$",
+                                    "line": None,
+                                    "command": None,
+                                    "hasParent": False,
+                                },
+                            ],
+                        },
+                        {
+                            "path": "^object/CMakeLists\\.txt$",
+                            "isGenerated": None,
+                            "fileSetName": None,
+                            "sourceGroupName": "",
+                            "compileGroupLanguage": None,
+                            "backtrace": [
+                                {
+                                    "file": "^CMakeLists\\.txt$",
+                                    "line": None,
+                                    "command": None,
+                                    "hasParent": False,
+                                },
+                            ],
+                        },
+                        {
+                            "path": "^subdir/CMakeLists\\.txt$",
+                            "isGenerated": None,
+                            "fileSetName": None,
+                            "sourceGroupName": "",
+                            "compileGroupLanguage": None,
+                            "backtrace": [
+                                {
+                                    "file": "^CMakeLists\\.txt$",
+                                    "line": None,
+                                    "command": None,
+                                    "hasParent": False,
+                                },
+                            ],
+                        },
                         {
                         {
                             "path": "^.*/Tests/RunCMake/FileAPI/codemodel-v2-build/CMakeFiles/([0-9a-f]+/)?generate\\.stamp\\.rule$",
                             "path": "^.*/Tests/RunCMake/FileAPI/codemodel-v2-build/CMakeFiles/([0-9a-f]+/)?generate\\.stamp\\.rule$",
                             "isGenerated": True,
                             "isGenerated": True,
@@ -866,6 +1062,24 @@ def gen_check_targets(c, g, inSource):
                         },
                         },
                     ]
                     ]
                     e["sourceGroups"] = [
                     e["sourceGroups"] = [
+                        {
+                            "name": "",
+                            "sourcePaths": [
+                                "^CMakeLists\\.txt$",
+                                "^alias/CMakeLists\\.txt$",
+                                "^codemodel-v2\\.cmake$",
+                                "^custom/CMakeLists\\.txt$",
+                                "^cxx/CMakeLists\\.txt$",
+                                "^dir/CMakeLists\\.txt$",
+                                "^dir/dir/CMakeLists\\.txt$",
+                                "^fileset/CMakeLists\\.txt$",
+                                "^imported/CMakeLists\\.txt$",
+                                "^include_test\\.cmake$",
+                                "^interface/CMakeLists\\.txt$",
+                                "^object/CMakeLists\\.txt$",
+                                "^subdir/CMakeLists\\.txt$",
+                            ],
+                        },
                         {
                         {
                             "name": "CMake Rules",
                             "name": "CMake Rules",
                             "sourcePaths": [
                             "sourcePaths": [

+ 25 - 0
Tests/RunCMake/VS10Project/CMakeInputs-check.cmake

@@ -0,0 +1,25 @@
+set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/ZERO_CHECK.vcxproj")
+if(NOT EXISTS "${vcProjectFile}")
+  set(RunCMake_TEST_FAILED "Project file ${vcProjectFile} does not exist.")
+  return()
+endif()
+
+set(found_CMakeInputs 0)
+file(STRINGS "${vcProjectFile}" lines)
+foreach(line IN LISTS lines)
+  if(line MATCHES "<([A-Za-z0-9_]+) +Include=.*CMakeInputs.cmake")
+    set(rule "${CMAKE_MATCH_1}")
+    if(NOT rule STREQUAL "None")
+      set(RunCMake_TEST_FAILED "CMakeInputs.cmake referenced as ${rule} instead of None")
+      return()
+    endif()
+    if(found_CMakeInputs)
+      set(RunCMake_TEST_FAILED "CMakeInputs.cmake referenced multiple times")
+      return()
+    endif()
+    set(found_CMakeInputs 1)
+  endif()
+endforeach()
+if(NOT found_CMakeInputs)
+  set(RunCMake_TEST_FAILED "CMakeInputs.cmake not referenced")
+endif()

+ 0 - 0
Tests/RunCMake/VS10Project/CMakeInputs.cmake


+ 1 - 0
Tests/RunCMake/VS10Project/RunCMakeTest.cmake

@@ -7,6 +7,7 @@ if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND CMAKE_C_COMPILER_VERSION VERSION_GREA
   run_cmake(LanguageStandard)
   run_cmake(LanguageStandard)
 endif()
 endif()
 
 
+run_cmake(CMakeInputs)
 run_cmake(CustomCommandGenex)
 run_cmake(CustomCommandGenex)
 if(NOT RunCMake_GENERATOR MATCHES "^Visual Studio 1[1-5] ")
 if(NOT RunCMake_GENERATOR MATCHES "^Visual Studio 1[1-5] ")
   run_cmake(CustomCommandParallel)
   run_cmake(CustomCommandParallel)