From c2ba6ba4fc0d807f36a6a9fcb1c166b776750dae Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 27 Apr 2012 09:21:08 -0400 Subject: [PATCH] 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. --- Source/cmVisualStudio10TargetGenerator.cxx | 78 +++++----------------- Source/cmVisualStudio10TargetGenerator.h | 13 +++- 2 files changed, 26 insertions(+), 65 deletions(-) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 9a0c5e1be..c4d5415c0 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -554,13 +554,6 @@ void cmVisualStudio10TargetGenerator::WriteGroups() std::vector classes = this->Target->GetSourceFiles(); std::set groupsUsed; - std::vector clCompile; - std::vector customBuild; - std::vector none; - std::vector headers; - std::vector idls; - std::vector resource; - for(std::vector::const_iterator s = classes.begin(); s != classes.end(); s++) { @@ -569,40 +562,6 @@ void cmVisualStudio10TargetGenerator::WriteGroups() cmSourceGroup& sourceGroup = this->Makefile->FindSourceGroup(source.c_str(), sourceGroups); 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); @@ -624,11 +583,11 @@ void cmVisualStudio10TargetGenerator::WriteGroups() "xmlns=\"http://schemas.microsoft.com/" "developer/msbuild/2003\">\n", 0); - this->WriteGroupSources("ClCompile", clCompile, sourceGroups); - this->WriteGroupSources("ClInclude", headers, sourceGroups); - this->WriteGroupSources("ResourceCompile", resource, sourceGroups); - this->WriteGroupSources("Midl", idls, sourceGroups); - this->WriteGroupSources("CustomBuild", customBuild, sourceGroups); + for(ToolSourceMap::const_iterator ti = this->Tools.begin(); + ti != this->Tools.end(); ++ti) + { + this->WriteGroupSources(ti->first.c_str(), ti->second, sourceGroups); + } // Add object library contents as external objects. std::vector objs; @@ -685,7 +644,6 @@ void cmVisualStudio10TargetGenerator::WriteGroups() this->WriteString("\n", 2); } this->WriteString("\n", 1); - this->WriteGroupSources("None", none, sourceGroups); this->WriteString("\n", 0); // restore stream pointer this->BuildFileStream = save; @@ -745,32 +703,23 @@ cmVisualStudio10TargetGenerator::AddMissingSourceGroups( void cmVisualStudio10TargetGenerator:: WriteGroupSources(const char* name, - std::vector const& sources, + ToolSources const& sources, std::vector& sourceGroups) { this->WriteString("\n", 1); - for(std::vector::const_iterator s = sources.begin(); + for(ToolSources::const_iterator s = sources.begin(); s != sources.end(); ++s) { - cmSourceFile* sf = *s; - if(sf->GetExtension() == "obj") - { - continue; - } + cmSourceFile* sf = s->SourceFile; std::string const& source = sf->GetFullPath(); cmSourceGroup& sourceGroup = this->Makefile->FindSourceGroup(source.c_str(), sourceGroups); const char* filter = sourceGroup.GetFullName(); this->WriteString("<", 2); - std::string path = source; - // custom command sources must use relative paths or they will - // not show up in the GUI. - if(sf->GetCustomCommand()) - { - path = cmSystemTools::RelativePath( + std::string path = s->RelativePath? + cmSystemTools::RelativePath( this->Makefile->GetCurrentOutputDirectory(), - source.c_str()); - } + source.c_str()) : source; this->ConvertToWindowsSlash(path); (*this->BuildFileStream) << name << " Include=\"" << path; @@ -794,7 +743,8 @@ void cmVisualStudio10TargetGenerator::WriteSource( const char* tool, cmSourceFile* sf, const char* end) { 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 // not show up in the GUI. @@ -811,6 +761,8 @@ void cmVisualStudio10TargetGenerator::WriteSource( this->WriteString("<", 2); (*this->BuildFileStream ) << tool << " Include=\"" << sourceFile << "\"" << (end? end : " />\n"); + ToolSource toolSource = {sf, relative}; + this->Tools[tool].push_back(toolSource); } void cmVisualStudio10TargetGenerator::WriteSources( diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h index 1e0f9c197..c00d328a6 100644 --- a/Source/cmVisualStudio10TargetGenerator.h +++ b/Source/cmVisualStudio10TargetGenerator.h @@ -43,6 +43,13 @@ public: ); private: + struct ToolSource + { + cmSourceFile* SourceFile; + bool RelativePath; + }; + struct ToolSources: public std::vector {}; + void ConvertToWindowsSlash(std::string& s); void WriteString(const char* line, int indentLevel); void WriteProjectConfigurations(); @@ -77,8 +84,7 @@ private: void WriteEvents(std::string const& configName); void WriteEvent(const char* name, std::vector & commands, std::string const& configName); - void WriteGroupSources(const char* name, - std::vector const& sources, + void WriteGroupSources(const char* name, ToolSources const& sources, std::vector& ); void AddMissingSourceGroups(std::set& groupsUsed, const std::vector& allGroups); @@ -99,6 +105,9 @@ private: cmGeneratedFileStream* BuildFileStream; cmLocalVisualStudio7Generator* LocalGenerator; std::set SourcesVisited; + + typedef std::map ToolSourceMap; + ToolSourceMap Tools; }; #endif