From 545fdec4f8ed705f948080ed203dabc7ab3628d3 Mon Sep 17 00:00:00 2001 From: Anton Helwart Date: Mon, 4 Feb 2013 10:35:48 +0100 Subject: [PATCH] VS: Avoid empty source groups in some cases (#3474) Teach the WriteGroup method return true if a group or any of its children have source files. Have children write their output to a temporay cmOStringStream. Add it to the real output only if not empty. --- Source/cmLocalVisualStudio7Generator.cxx | 30 +++++++++++++++++------- Source/cmLocalVisualStudio7Generator.h | 2 +- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index f07ebef07..dfe828062 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -1621,17 +1621,30 @@ cmLocalVisualStudio7Generator return dir_max; } -void cmLocalVisualStudio7Generator +bool cmLocalVisualStudio7Generator ::WriteGroup(const cmSourceGroup *sg, cmTarget& target, std::ostream &fout, const char *libName, std::vector *configs) { const std::vector &sourceFiles = sg->GetSourceFiles(); - // If the group is empty, don't write it at all. - if(sourceFiles.empty() && sg->GetGroupChildren().empty()) + std::vector const& children = sg->GetGroupChildren(); + + // Write the children to temporary output. + bool hasChildrenWithSources = false; + cmOStringStream tmpOut; + for(unsigned int i=0;iWriteGroup(&children[i], target, tmpOut, libName, configs)) + { + hasChildrenWithSources = true; + } + } + + // If the group is empty, don't write it at all. + if(sourceFiles.empty() && !hasChildrenWithSources) + { + return false; } // If the group has a name, write the header. @@ -1752,11 +1765,10 @@ void cmLocalVisualStudio7Generator } } - std::vector const& children = sg->GetGroupChildren(); - - for(unsigned int i=0;iWriteGroup(&children[i], target, fout, libName, configs); + fout << tmpOut.str(); } // If the group has a name, write the footer. @@ -1764,6 +1776,8 @@ void cmLocalVisualStudio7Generator { this->WriteVCProjEndGroup(fout); } + + return true; } void cmLocalVisualStudio7Generator:: diff --git a/Source/cmLocalVisualStudio7Generator.h b/Source/cmLocalVisualStudio7Generator.h index 5a1d208ef..d9e2ef0dd 100644 --- a/Source/cmLocalVisualStudio7Generator.h +++ b/Source/cmLocalVisualStudio7Generator.h @@ -109,7 +109,7 @@ private: FCInfo& fcinfo); void WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target); - void WriteGroup(const cmSourceGroup *sg, + bool WriteGroup(const cmSourceGroup *sg, cmTarget& target, std::ostream &fout, const char *libName, std::vector *configs);