VS: Add CMake input files to ZERO_CHECK

Add all cmake input files to the `ZERO_CHECK` project.  Place files
under `CMAKE_SOURCE_DIR` in a folder structure matching the directory
structure.  This way they are easier to find, and Visual Studio does not
close them when reloading the project.

Fixes: #24557
This commit is contained in:
Alexander Neundorf
2023-03-19 23:30:02 +01:00
committed by Brad King
parent 659e9ae937
commit df58dbb0e9
7 changed files with 315 additions and 1 deletions

View File

@@ -9,6 +9,7 @@
#include <set>
#include <sstream>
#include <cm/filesystem>
#include <cm/memory>
#include <cm/optional>
#include <cm/string_view>
@@ -51,6 +52,8 @@
#include "cmValue.h"
#include "cmVisualStudioGeneratorOptions.h"
const std::string kBuildSystemSources = "Buildsystem Input Files";
struct cmIDEFlagTable;
static void ConvertToWindowsSlash(std::string& s);
@@ -1950,7 +1953,13 @@ void cmVisualStudio10TargetGenerator::WriteGroups()
"http://schemas.microsoft.com/developer/msbuild/2003");
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.
@@ -2021,6 +2030,18 @@ void cmVisualStudio10TargetGenerator::WriteGroups()
"rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;"
"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';
@@ -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(
Elem& e1, cmSourceFile const* sf, ConfigToSettings const& toolSettings)
{