diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx index 968145c2d0..a81c4a11de 100644 --- a/Source/cmExtraEclipseCDT4Generator.cxx +++ b/Source/cmExtraEclipseCDT4Generator.cxx @@ -518,8 +518,6 @@ void cmExtraEclipseCDT4Generator::CreateLinksForTargets(cmXMLWriter& xml) if (!this->GenerateLinkedResources) { break; // skip generating the linked resources to the source files } - std::vector sourceGroups = - makefile->GetSourceGroups(); // get the files from the source lists then add them to the groups std::vector files; target->GetSourceFiles( @@ -527,11 +525,12 @@ void cmExtraEclipseCDT4Generator::CreateLinksForTargets(cmXMLWriter& xml) for (cmSourceFile* sf : files) { // Add the file to the list of sources. std::string const& source = sf->ResolveFullPath(); - cmSourceGroup* sourceGroup = - makefile->FindSourceGroup(source, sourceGroups); + cmSourceGroup* sourceGroup = makefile->FindSourceGroup(source); sourceGroup->AssignSource(sf); } + std::vector sourceGroups = + makefile->GetSourceGroups(); this->WriteGroups(sourceGroups, linkName2, xml); } break; // ignore all others: diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx index 31daa771ab..976ab7a005 100644 --- a/Source/cmFileAPICodemodel.cxx +++ b/Source/cmFileAPICodemodel.cxx @@ -439,7 +439,6 @@ class Target std::string const& Config; std::string TopSource; std::string TopBuild; - std::vector SourceGroupsLocal; BacktraceData Backtraces; std::map CompileDataMap; @@ -1256,7 +1255,6 @@ Target::Target(cmGeneratorTarget* gt, unsigned int versionMajor, , TopSource(gt->GetGlobalGenerator()->GetCMakeInstance()->GetHomeDirectory()) , TopBuild( gt->GetGlobalGenerator()->GetCMakeInstance()->GetHomeOutputDirectory()) - , SourceGroupsLocal(this->GT->Makefile->GetSourceGroups()) , Backtraces(this->TopSource) { } @@ -1815,8 +1813,7 @@ Json::Value Target::DumpSource(cmGeneratorTarget::SourceAndKind const& sk, source["fileSetIndex"] = fsit->second; } - if (cmSourceGroup* sg = - this->GT->Makefile->FindSourceGroup(path, this->SourceGroupsLocal)) { + if (cmSourceGroup* sg = this->GT->Makefile->FindSourceGroup(path)) { source["sourceGroupIndex"] = this->AddSourceGroup(sg, si); } diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index 7443d11629..51554cef3b 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -509,17 +509,12 @@ void cmGhsMultiTargetGenerator::WriteSources(std::ostream& fout_proj) std::vector sources; this->GeneratorTarget->GetSourceFiles(sources, this->ConfigName); - /* vector of all groups defined for this target - * -- but the vector is not expanded with sub groups or in any useful order - */ - std::vector sourceGroups = this->Makefile->GetSourceGroups(); - /* for each source file assign it to its group */ std::map> groupFiles; std::set groupNames; for (cmSourceFile* sf : sources) { cmSourceGroup* sourceGroup = - this->Makefile->FindSourceGroup(sf->ResolveFullPath(), sourceGroups); + this->Makefile->FindSourceGroup(sf->ResolveFullPath()); std::string gn = sourceGroup->GetFullName(); groupFiles[gn].push_back(sf); groupNames.insert(std::move(gn)); diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index 759806f48e..957c7c4e61 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -1051,9 +1051,6 @@ cm::VS::Solution cmGlobalVisualStudioGenerator::CreateSolution( } cmMakefile* mf = root->GetMakefile(); - // Unfortunately we have to copy the source groups because - // FindSourceGroup uses a regex which is modifying the group. - std::vector sourceGroups = mf->GetSourceGroups(); std::vector items = cmList{ root->GetMakefile()->GetProperty("VS_SOLUTION_ITEMS") }; for (std::string item : items) { @@ -1061,7 +1058,7 @@ cm::VS::Solution cmGlobalVisualStudioGenerator::CreateSolution( item = cmSystemTools::CollapseFullPath(item, mf->GetCurrentSourceDirectory()); } - cmSourceGroup* sg = mf->FindSourceGroup(item, sourceGroups); + cmSourceGroup* sg = mf->FindSourceGroup(item); std::string folderName = sg->GetFullName(); if (folderName.empty()) { folderName = "Solution Items"_s; diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 2f5df554b2..e03b3d9d3c 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -4500,7 +4500,6 @@ bool cmGlobalXCodeGenerator::CreateGroups( { for (auto& generator : generators) { cmMakefile* mf = generator->GetMakefile(); - std::vector sourceGroups = mf->GetSourceGroups(); for (auto const& gtgt : generator->GetGeneratorTargets()) { // Same skipping logic here as in CreateXCodeTargets so that we do not // end up with (empty anyhow) ZERO_CHECK, install, or test source @@ -4512,9 +4511,8 @@ bool cmGlobalXCodeGenerator::CreateGroups( continue; } - auto addSourceToGroup = [this, mf, >gt, - &sourceGroups](std::string const& source) { - cmSourceGroup* sourceGroup = mf->FindSourceGroup(source, sourceGroups); + auto addSourceToGroup = [this, mf, >gt](std::string const& source) { + cmSourceGroup* sourceGroup = mf->FindSourceGroup(source); cmXCodeObject* pbxgroup = this->CreateOrGetPBXGroup(gtgt.get(), sourceGroup); std::string key = GetGroupMapKeyFromPath(gtgt.get(), source); diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index cd0e67832a..45c0e8a40a 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -1406,9 +1406,6 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout, std::vector configs = this->Makefile->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig); - // We may be modifying the source groups temporarily, so make a copy. - std::vector sourceGroups = this->Makefile->GetSourceGroups(); - AllConfigSources sources; sources.Sources = target->GetAllConfigSources(); @@ -1450,8 +1447,7 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout, } // Add the file to the list of sources. std::string const source = sf->GetFullPath(); - cmSourceGroup* sourceGroup = - this->Makefile->FindSourceGroup(source, sourceGroups); + cmSourceGroup* sourceGroup = this->Makefile->FindSourceGroup(source); sourceGroup->AssignSource(sf); } @@ -1463,6 +1459,7 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout, fout << "\t\n"; // Loop through every source group. + std::vector sourceGroups = this->Makefile->GetSourceGroups(); for (auto const& sg : sourceGroups) { this->WriteGroup(&sg, target, fout, libName, configs, sources); } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 0320c2e214..e006ebe8b6 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2193,11 +2193,10 @@ cmSourceGroup* cmMakefile::GetOrCreateSourceGroup(std::string const& name) * non-inherited SOURCE_GROUP commands will have precedence over * inherited ones. */ -cmSourceGroup* cmMakefile::FindSourceGroup( - std::string const& source, std::vector& groups) const +cmSourceGroup* cmMakefile::FindSourceGroup(std::string const& source) { // First search for a group that lists the file explicitly. - for (auto sg = groups.rbegin(); sg != groups.rend(); ++sg) { + for (auto sg = SourceGroups.rbegin(); sg != SourceGroups.rend(); ++sg) { cmSourceGroup* result = sg->MatchChildrenFiles(source); if (result) { return result; @@ -2205,7 +2204,7 @@ cmSourceGroup* cmMakefile::FindSourceGroup( } // Now search for a group whose regex matches the file. - for (auto sg = groups.rbegin(); sg != groups.rend(); ++sg) { + for (auto sg = SourceGroups.rbegin(); sg != SourceGroups.rend(); ++sg) { cmSourceGroup* result = sg->MatchChildrenRegex(source); if (result) { return result; @@ -2213,7 +2212,7 @@ cmSourceGroup* cmMakefile::FindSourceGroup( } // Shouldn't get here, but just in case, return the default group. - return groups.data(); + return SourceGroups.data(); } #endif diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 3acd06f66c..851d4f40d2 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -658,8 +658,7 @@ public: /** * find what source group this source is in */ - cmSourceGroup* FindSourceGroup(std::string const& source, - std::vector& groups) const; + cmSourceGroup* FindSourceGroup(std::string const& source); #endif /** diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 23d7fd6d77..bcba6d2ef7 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -1993,29 +1993,24 @@ void cmVisualStudio10TargetGenerator::WriteGroups() return; } - // collect up group information - std::vector sourceGroups = this->Makefile->GetSourceGroups(); - std::vector const& sources = this->GeneratorTarget->GetAllConfigSources(); std::set groupsUsed; for (cmGeneratorTarget::AllConfigSource const& si : sources) { std::string const& source = si.Source->GetFullPath(); - cmSourceGroup* sourceGroup = - this->Makefile->FindSourceGroup(source, sourceGroups); + cmSourceGroup* sourceGroup = this->Makefile->FindSourceGroup(source); groupsUsed.insert(sourceGroup); } if (cmSourceFile const* srcCMakeLists = this->LocalGenerator->CreateVCProjBuildRule()) { std::string const& source = srcCMakeLists->GetFullPath(); - cmSourceGroup* sourceGroup = - this->Makefile->FindSourceGroup(source, sourceGroups); + cmSourceGroup* sourceGroup = this->Makefile->FindSourceGroup(source); groupsUsed.insert(sourceGroup); } - this->AddMissingSourceGroups(groupsUsed, sourceGroups); + this->AddMissingSourceGroups(groupsUsed, this->Makefile->GetSourceGroups()); // Write out group file std::string path = cmStrCat( @@ -2035,7 +2030,7 @@ void cmVisualStudio10TargetGenerator::WriteGroups() "http://schemas.microsoft.com/developer/msbuild/2003"); for (auto const& ti : this->Tools) { - this->WriteGroupSources(e0, ti.first, ti.second, sourceGroups); + this->WriteGroupSources(e0, ti.first, ti.second); } // Added files are images and the manifest. @@ -2163,16 +2158,14 @@ void cmVisualStudio10TargetGenerator::AddMissingSourceGroups( } void cmVisualStudio10TargetGenerator::WriteGroupSources( - Elem& e0, std::string const& name, ToolSources const& sources, - std::vector& sourceGroups) + Elem& e0, std::string const& name, ToolSources const& sources) { Elem e1(e0, "ItemGroup"); e1.SetHasElements(); for (ToolSource const& s : sources) { cmSourceFile const* sf = s.SourceFile; std::string const& source = sf->GetFullPath(); - cmSourceGroup* sourceGroup = - this->Makefile->FindSourceGroup(source, sourceGroups); + cmSourceGroup* sourceGroup = this->Makefile->FindSourceGroup(source); std::string const& filter = sourceGroup->GetFullName(); std::string path = this->ConvertPath(source, s.RelativePath); ConvertToWindowsSlash(path); @@ -6043,11 +6036,7 @@ std::string cmVisualStudio10TargetGenerator::GetCSharpSourceLink( std::string const& fullFileName = source->GetFullPath(); std::string const& srcDir = this->Makefile->GetCurrentSourceDirectory(); std::string const& binDir = this->Makefile->GetCurrentBinaryDirectory(); - // unfortunately we have to copy the source groups, because - // FindSourceGroup uses a regex which is modifying the group - std::vector sourceGroups = this->Makefile->GetSourceGroups(); - cmSourceGroup* sourceGroup = - this->Makefile->FindSourceGroup(fullFileName, sourceGroups); + cmSourceGroup* sourceGroup = this->Makefile->FindSourceGroup(fullFileName); if (sourceGroup && !sourceGroup->GetFullName().empty()) { sourceGroupedFile = cmStrCat(sourceGroup->GetFullName(), '/', diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h index 1bfc92916b..eae440fd92 100644 --- a/Source/cmVisualStudio10TargetGenerator.h +++ b/Source/cmVisualStudio10TargetGenerator.h @@ -202,8 +202,7 @@ private: std::vector const& commands, std::string const& configName); void WriteGroupSources(Elem& e0, std::string const& name, - ToolSources const& sources, - std::vector&); + ToolSources const& sources); void AddMissingSourceGroups(std::set& groupsUsed, std::vector const& allGroups); bool IsResxHeader(std::string const& headerFile);