diff options
author | Brad King <brad.king@kitware.com> | 2017-04-10 15:37:49 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-04-13 20:10:32 (GMT) |
commit | 97cc29c7662f51f0e532f92e37070f9b44791b88 (patch) | |
tree | 7d048531d0208743c4acf9b36f6046547f73b0c7 /Source/cmVisualStudio10TargetGenerator.cxx | |
parent | 2f6f6f0c153f19f7efab96b2a4c3c9c05362372b (diff) | |
download | CMake-97cc29c7662f51f0e532f92e37070f9b44791b88.zip CMake-97cc29c7662f51f0e532f92e37070f9b44791b88.tar.gz CMake-97cc29c7662f51f0e532f92e37070f9b44791b88.tar.bz2 |
VS: Teach generators how to mark per-config source files
Add internal infrastructure for looping over all sources for all
configurations and generating each source with exclusion marks
for configurations in which they do not participate. This does
not yet make per-config sources available in general but does
set up some of the needed infrastructure.
Unfortunately doing this cleanly will require major refactoring of both
the VS 7-9 generators and the VS 10+ generators (for separate reasons).
Instead add some extra internal structures to carry information where we
need it.
Diffstat (limited to 'Source/cmVisualStudio10TargetGenerator.cxx')
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.cxx | 66 |
1 files changed, 52 insertions, 14 deletions
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 8e6014a..fbfc1ed 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -1241,16 +1241,15 @@ void cmVisualStudio10TargetGenerator::WriteGroups() // collect up group information std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups(); - std::vector<cmSourceFile*> classes; - if (!this->GeneratorTarget->GetConfigCommonSourceFiles(classes)) { - return; - } + + std::vector<cmGeneratorTarget::AllConfigSource> const& sources = + this->GeneratorTarget->GetAllConfigSources(); std::set<cmSourceGroup*> groupsUsed; - for (std::vector<cmSourceFile*>::const_iterator s = classes.begin(); - s != classes.end(); s++) { - cmSourceFile* sf = *s; - std::string const& source = sf->GetFullPath(); + for (std::vector<cmGeneratorTarget::AllConfigSource>::const_iterator si = + sources.begin(); + si != sources.end(); ++si) { + std::string const& source = si->Source->GetFullPath(); cmSourceGroup* sourceGroup = this->Makefile->FindSourceGroup(source.c_str(), sourceGroups); groupsUsed.insert(sourceGroup); @@ -1734,12 +1733,17 @@ void cmVisualStudio10TargetGenerator::WriteAllSources() } this->WriteString("<ItemGroup>\n", 1); - cmGeneratorTarget::KindedSources const& sources = - this->GeneratorTarget->GetKindedSources(""); + std::vector<size_t> all_configs; + for (size_t ci = 0; ci < this->Configurations.size(); ++ci) { + all_configs.push_back(ci); + } + + std::vector<cmGeneratorTarget::AllConfigSource> const& sources = + this->GeneratorTarget->GetAllConfigSources(); - for (std::vector<cmGeneratorTarget::SourceAndKind>::const_iterator si = - sources.Sources.begin(); - si != sources.Sources.end(); ++si) { + for (std::vector<cmGeneratorTarget::AllConfigSource>::const_iterator si = + sources.begin(); + si != sources.end(); ++si) { std::string tool; switch (si->Kind) { case cmGeneratorTarget::SourceKindAppManifest: @@ -1810,14 +1814,35 @@ void cmVisualStudio10TargetGenerator::WriteAllSources() } if (!tool.empty()) { + // Compute set of configurations to exclude, if any. + std::vector<size_t> const& include_configs = si->Configs; + std::vector<size_t> exclude_configs; + std::set_difference(all_configs.begin(), all_configs.end(), + include_configs.begin(), include_configs.end(), + std::back_inserter(exclude_configs)); + if (si->Kind == cmGeneratorTarget::SourceKindObjectSource) { + // FIXME: refactor generation to avoid tracking XML syntax state. this->WriteSource(tool, si->Source, " "); - if (this->OutputSourceSpecificFlags(si->Source)) { + bool have_nested = this->OutputSourceSpecificFlags(si->Source); + if (!exclude_configs.empty()) { + if (!have_nested) { + (*this->BuildFileStream) << ">\n"; + } + this->WriteExcludeFromBuild(exclude_configs); + have_nested = true; + } + if (have_nested) { this->WriteString("</", 2); (*this->BuildFileStream) << tool << ">\n"; } else { (*this->BuildFileStream) << " />\n"; } + } else if (!exclude_configs.empty()) { + this->WriteSource(tool, si->Source, ">\n"); + this->WriteExcludeFromBuild(exclude_configs); + this->WriteString("</", 2); + (*this->BuildFileStream) << tool << ">\n"; } else { this->WriteSource(tool, si->Source); } @@ -2001,6 +2026,19 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( return hasFlags; } +void cmVisualStudio10TargetGenerator::WriteExcludeFromBuild( + std::vector<size_t> const& exclude_configs) +{ + for (std::vector<size_t>::const_iterator ci = exclude_configs.begin(); + ci != exclude_configs.end(); ++ci) { + this->WriteString("", 3); + (*this->BuildFileStream) + << "<ExcludedFromBuild Condition=\"'$(Configuration)|$(Platform)'=='" + << cmVS10EscapeXML(this->Configurations[*ci]) << "|" + << cmVS10EscapeXML(this->Platform) << "'\">true</ExcludedFromBuild>\n"; + } +} + void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions() { cmStateEnums::TargetType ttype = this->GeneratorTarget->GetType(); |