VS10: Simplify vcxproj.filter file generation

Remove the duplicate source file classification logic used to generate
the filter files.  Instead record during the main vcxproj file
generation the source files generated for each tool.  Also record
whether or not each source file is converted to a relative path.  Use
the recorded result during filter generation to ensure consistency
between the project file and filter file.
This commit is contained in:
Brad King 2012-04-27 09:21:08 -04:00
parent 4f2d9d2da5
commit c2ba6ba4fc
2 changed files with 26 additions and 65 deletions

View File

@ -554,13 +554,6 @@ void cmVisualStudio10TargetGenerator::WriteGroups()
std::vector<cmSourceFile*> classes = this->Target->GetSourceFiles(); std::vector<cmSourceFile*> classes = this->Target->GetSourceFiles();
std::set<cmSourceGroup*> groupsUsed; std::set<cmSourceGroup*> groupsUsed;
std::vector<cmSourceFile*> clCompile;
std::vector<cmSourceFile*> customBuild;
std::vector<cmSourceFile*> none;
std::vector<cmSourceFile*> headers;
std::vector<cmSourceFile*> idls;
std::vector<cmSourceFile*> resource;
for(std::vector<cmSourceFile*>::const_iterator s = classes.begin(); for(std::vector<cmSourceFile*>::const_iterator s = classes.begin();
s != classes.end(); s++) s != classes.end(); s++)
{ {
@ -569,40 +562,6 @@ void cmVisualStudio10TargetGenerator::WriteGroups()
cmSourceGroup& sourceGroup = cmSourceGroup& sourceGroup =
this->Makefile->FindSourceGroup(source.c_str(), sourceGroups); this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
groupsUsed.insert(&sourceGroup); groupsUsed.insert(&sourceGroup);
const char* lang = sf->GetLanguage();
bool header = (*s)->GetPropertyAsBool("HEADER_FILE_ONLY")
|| this->GlobalGenerator->IgnoreFile
((*s)->GetExtension().c_str());
std::string ext =
cmSystemTools::LowerCase((*s)->GetExtension());
if(!lang)
{
lang = "None";
}
if(header)
{
headers.push_back(sf);
}
else if(lang[0] == 'C')
{
clCompile.push_back(sf);
}
else if(strcmp(lang, "RC") == 0)
{
resource.push_back(sf);
}
else if(sf->GetCustomCommand())
{
customBuild.push_back(sf);
}
else if(ext == "idl")
{
idls.push_back(sf);
}
else
{
none.push_back(sf);
}
} }
this->AddMissingSourceGroups(groupsUsed, sourceGroups); this->AddMissingSourceGroups(groupsUsed, sourceGroups);
@ -624,11 +583,11 @@ void cmVisualStudio10TargetGenerator::WriteGroups()
"xmlns=\"http://schemas.microsoft.com/" "xmlns=\"http://schemas.microsoft.com/"
"developer/msbuild/2003\">\n", "developer/msbuild/2003\">\n",
0); 0);
this->WriteGroupSources("ClCompile", clCompile, sourceGroups); for(ToolSourceMap::const_iterator ti = this->Tools.begin();
this->WriteGroupSources("ClInclude", headers, sourceGroups); ti != this->Tools.end(); ++ti)
this->WriteGroupSources("ResourceCompile", resource, sourceGroups); {
this->WriteGroupSources("Midl", idls, sourceGroups); this->WriteGroupSources(ti->first.c_str(), ti->second, sourceGroups);
this->WriteGroupSources("CustomBuild", customBuild, sourceGroups); }
// Add object library contents as external objects. // Add object library contents as external objects.
std::vector<std::string> objs; std::vector<std::string> objs;
@ -685,7 +644,6 @@ void cmVisualStudio10TargetGenerator::WriteGroups()
this->WriteString("</Filter>\n", 2); this->WriteString("</Filter>\n", 2);
} }
this->WriteString("</ItemGroup>\n", 1); this->WriteString("</ItemGroup>\n", 1);
this->WriteGroupSources("None", none, sourceGroups);
this->WriteString("</Project>\n", 0); this->WriteString("</Project>\n", 0);
// restore stream pointer // restore stream pointer
this->BuildFileStream = save; this->BuildFileStream = save;
@ -745,32 +703,23 @@ cmVisualStudio10TargetGenerator::AddMissingSourceGroups(
void void
cmVisualStudio10TargetGenerator:: cmVisualStudio10TargetGenerator::
WriteGroupSources(const char* name, WriteGroupSources(const char* name,
std::vector<cmSourceFile*> const& sources, ToolSources const& sources,
std::vector<cmSourceGroup>& sourceGroups) std::vector<cmSourceGroup>& sourceGroups)
{ {
this->WriteString("<ItemGroup>\n", 1); this->WriteString("<ItemGroup>\n", 1);
for(std::vector<cmSourceFile*>::const_iterator s = sources.begin(); for(ToolSources::const_iterator s = sources.begin();
s != sources.end(); ++s) s != sources.end(); ++s)
{ {
cmSourceFile* sf = *s; cmSourceFile* sf = s->SourceFile;
if(sf->GetExtension() == "obj")
{
continue;
}
std::string const& source = sf->GetFullPath(); std::string const& source = sf->GetFullPath();
cmSourceGroup& sourceGroup = cmSourceGroup& sourceGroup =
this->Makefile->FindSourceGroup(source.c_str(), sourceGroups); this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
const char* filter = sourceGroup.GetFullName(); const char* filter = sourceGroup.GetFullName();
this->WriteString("<", 2); this->WriteString("<", 2);
std::string path = source; std::string path = s->RelativePath?
// custom command sources must use relative paths or they will cmSystemTools::RelativePath(
// not show up in the GUI.
if(sf->GetCustomCommand())
{
path = cmSystemTools::RelativePath(
this->Makefile->GetCurrentOutputDirectory(), this->Makefile->GetCurrentOutputDirectory(),
source.c_str()); source.c_str()) : source;
}
this->ConvertToWindowsSlash(path); this->ConvertToWindowsSlash(path);
(*this->BuildFileStream) << name << " Include=\"" (*this->BuildFileStream) << name << " Include=\""
<< path; << path;
@ -794,7 +743,8 @@ void cmVisualStudio10TargetGenerator::WriteSource(
const char* tool, cmSourceFile* sf, const char* end) const char* tool, cmSourceFile* sf, const char* end)
{ {
std::string sourceFile = sf->GetFullPath(); std::string sourceFile = sf->GetFullPath();
if(sf->GetCustomCommand()) bool relative = sf->GetCustomCommand()? true:false;
if(relative)
{ {
// custom command sources must use relative paths or they will // custom command sources must use relative paths or they will
// not show up in the GUI. // not show up in the GUI.
@ -811,6 +761,8 @@ void cmVisualStudio10TargetGenerator::WriteSource(
this->WriteString("<", 2); this->WriteString("<", 2);
(*this->BuildFileStream ) << tool << (*this->BuildFileStream ) << tool <<
" Include=\"" << sourceFile << "\"" << (end? end : " />\n"); " Include=\"" << sourceFile << "\"" << (end? end : " />\n");
ToolSource toolSource = {sf, relative};
this->Tools[tool].push_back(toolSource);
} }
void cmVisualStudio10TargetGenerator::WriteSources( void cmVisualStudio10TargetGenerator::WriteSources(

View File

@ -43,6 +43,13 @@ public:
); );
private: private:
struct ToolSource
{
cmSourceFile* SourceFile;
bool RelativePath;
};
struct ToolSources: public std::vector<ToolSource> {};
void ConvertToWindowsSlash(std::string& s); void ConvertToWindowsSlash(std::string& s);
void WriteString(const char* line, int indentLevel); void WriteString(const char* line, int indentLevel);
void WriteProjectConfigurations(); void WriteProjectConfigurations();
@ -77,8 +84,7 @@ private:
void WriteEvents(std::string const& configName); void WriteEvents(std::string const& configName);
void WriteEvent(const char* name, std::vector<cmCustomCommand> & commands, void WriteEvent(const char* name, std::vector<cmCustomCommand> & commands,
std::string const& configName); std::string const& configName);
void WriteGroupSources(const char* name, void WriteGroupSources(const char* name, ToolSources const& sources,
std::vector<cmSourceFile*> const& sources,
std::vector<cmSourceGroup>& ); std::vector<cmSourceGroup>& );
void AddMissingSourceGroups(std::set<cmSourceGroup*>& groupsUsed, void AddMissingSourceGroups(std::set<cmSourceGroup*>& groupsUsed,
const std::vector<cmSourceGroup>& allGroups); const std::vector<cmSourceGroup>& allGroups);
@ -99,6 +105,9 @@ private:
cmGeneratedFileStream* BuildFileStream; cmGeneratedFileStream* BuildFileStream;
cmLocalVisualStudio7Generator* LocalGenerator; cmLocalVisualStudio7Generator* LocalGenerator;
std::set<cmSourceFile*> SourcesVisited; std::set<cmSourceFile*> SourcesVisited;
typedef std::map<cmStdString, ToolSources> ToolSourceMap;
ToolSourceMap Tools;
}; };
#endif #endif