1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 19:08:07 +08:00

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

@@ -273,6 +273,22 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
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* gt = ptr.get();
lg.AddGeneratorTarget(std::move(ptr));

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)
{

View File

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

View File

@@ -848,7 +848,203 @@ def gen_check_targets(c, g, inSource):
for e in expected:
if e["type"] == "UTILITY":
if e["id"] == "^ZERO_CHECK::@6890427a1f51a3e7e1df$":
# The json files have data for Xcode. Substitute data for VS.
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$",
"isGenerated": True,
@@ -866,6 +1062,24 @@ def gen_check_targets(c, g, inSource):
},
]
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",
"sourcePaths": [

View File

@@ -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()

View File

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