diff options
Diffstat (limited to 'Source/cmVisualStudio10TargetGenerator.cxx')
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.cxx | 822 |
1 files changed, 435 insertions, 387 deletions
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index c61902ab6..ec31bd628 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -15,8 +15,11 @@ #include "cmVisualStudioGeneratorOptions.h" #include "windows.h" +#include <iterator> #include <memory> // IWYU pragma: keep +static void ConvertToWindowsSlash(std::string& s); + static std::string cmVS10EscapeXML(std::string arg) { cmSystemTools::ReplaceString(arg, "&", "&"); @@ -37,8 +40,8 @@ static std::string cmVS10EscapeComment(std::string comment) // does "echo $CDATA" with no escapes. We must encode the string. // http://technet.microsoft.com/en-us/library/cc772462%28WS.10%29.aspx std::string echoable; - for (std::string::iterator c = comment.begin(); c != comment.end(); ++c) { - switch (*c) { + for (char c : comment) { + switch (c) { case '\r': break; case '\n': @@ -51,8 +54,9 @@ static std::string cmVS10EscapeComment(std::string comment) case '>': /* no break */ case '^': echoable += '^'; /* no break */ + CM_FALLTHROUGH; default: - echoable += *c; + echoable += c; break; } } @@ -65,11 +69,14 @@ static bool cmVS10IsTargetsFile(std::string const& path) return cmSystemTools::Strucmp(ext.c_str(), ".targets") == 0; } -static std::string computeProjectFileExtension(cmGeneratorTarget const* t) +static std::string computeProjectFileExtension(cmGeneratorTarget const* t, + const std::string& config) { std::string res; res = ".vcxproj"; - if (cmGlobalVisualStudioGenerator::TargetIsCSharpOnly(t)) { + std::string lang = t->GetLinkerLanguage(config); + if (cmGlobalVisualStudioGenerator::TargetIsCSharpOnly(t) || + lang == "CSharp") { res = ".csproj"; } return res; @@ -109,22 +116,6 @@ cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator( cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator() { - for (OptionsMap::iterator i = this->ClOptions.begin(); - i != this->ClOptions.end(); ++i) { - delete i->second; - } - for (OptionsMap::iterator i = this->LinkOptions.begin(); - i != this->LinkOptions.end(); ++i) { - delete i->second; - } - for (OptionsMap::iterator i = this->CudaOptions.begin(); - i != this->CudaOptions.end(); ++i) { - delete i->second; - } - for (OptionsMap::iterator i = this->CudaLinkOptions.begin(); - i != this->CudaLinkOptions.end(); ++i) { - delete i->second; - } if (!this->BuildFileStream) { return; } @@ -198,8 +189,8 @@ void cmVisualStudio10TargetGenerator::Generate() this->GeneratorTarget->GetProperty("EXTERNAL_MSPROJECT")) { return; } - this->ProjectFileExtension = - computeProjectFileExtension(this->GeneratorTarget); + this->ProjectFileExtension = computeProjectFileExtension( + this->GeneratorTarget, *this->Configurations.begin()); if (this->ProjectFileExtension == ".vcxproj") { this->ProjectType = vcxproj; this->Managed = false; @@ -400,18 +391,17 @@ void cmVisualStudio10TargetGenerator::Generate() } std::vector<std::string> keys = this->GeneratorTarget->GetPropertyKeys(); - for (std::vector<std::string>::const_iterator keyIt = keys.begin(); - keyIt != keys.end(); ++keyIt) { + for (std::string const& keyIt : keys) { static const char* prefix = "VS_GLOBAL_"; - if (keyIt->find(prefix) != 0) + if (keyIt.find(prefix) != 0) continue; - std::string globalKey = keyIt->substr(strlen(prefix)); + std::string globalKey = keyIt.substr(strlen(prefix)); // Skip invalid or separately-handled properties. if (globalKey.empty() || globalKey == "PROJECT_TYPES" || globalKey == "ROOTNAMESPACE" || globalKey == "KEYWORD") { continue; } - const char* value = this->GeneratorTarget->GetProperty(*keyIt); + const char* value = this->GeneratorTarget->GetProperty(keyIt); if (!value) continue; this->WriteString("<", 2); @@ -494,7 +484,7 @@ void cmVisualStudio10TargetGenerator::Generate() std::string propsLocal; propsLocal += this->DefaultArtifactDir; propsLocal += "\\nasm.props"; - this->ConvertToWindowsSlash(propsLocal); + ConvertToWindowsSlash(propsLocal); this->Makefile->ConfigureFile(propsTemplate.c_str(), propsLocal.c_str(), false, true, true); std::string import = std::string("<Import Project=\"") + @@ -517,7 +507,7 @@ void cmVisualStudio10TargetGenerator::Generate() props = p; } if (!props.empty()) { - this->ConvertToWindowsSlash(props); + ConvertToWindowsSlash(props); this->WriteString("", 2); (*this->BuildFileStream) << "<Import Project=\"" << cmVS10EscapeXML(props) << "\"" @@ -573,22 +563,18 @@ void cmVisualStudio10TargetGenerator::Generate() } this->WriteString("</ImportGroup>\n", 1); if (this->ProjectType == csproj) { - for (std::vector<std::string>::const_iterator i = - this->Configurations.begin(); - i != this->Configurations.end(); ++i) { + for (std::string const& i : this->Configurations) { this->WriteString("<PropertyGroup Condition=\"'$(Configuration)' == '", 1); - (*this->BuildFileStream) << *i << "'\">\n"; - this->WriteEvents(*i); + (*this->BuildFileStream) << i << "'\">\n"; + this->WriteEvents(i); this->WriteString("</PropertyGroup>\n", 1); } // make sure custom commands are executed before build (if necessary) this->WriteString("<PropertyGroup>\n", 1); this->WriteString("<BuildDependsOn>\n", 2); - for (std::set<std::string>::const_iterator i = - this->CSharpCustomCommandNames.begin(); - i != this->CSharpCustomCommandNames.end(); ++i) { - this->WriteString(i->c_str(), 3); + for (std::string const& i : this->CSharpCustomCommandNames) { + this->WriteString(i.c_str(), 3); (*this->BuildFileStream) << ";\n"; } this->WriteString("$(BuildDependsOn)\n", 3); @@ -610,42 +596,37 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReferences() cmSystemTools::ExpandListArgument(vsDotNetReferences, references); } cmPropertyMap const& props = this->GeneratorTarget->Target->GetProperties(); - for (cmPropertyMap::const_iterator i = props.begin(); i != props.end(); - ++i) { - if (i->first.find("VS_DOTNET_REFERENCE_") == 0) { - std::string name = i->first.substr(20); + for (auto const& i : props) { + if (i.first.find("VS_DOTNET_REFERENCE_") == 0) { + std::string name = i.first.substr(20); if (!name.empty()) { - std::string path = i->second.GetValue(); + std::string path = i.second.GetValue(); if (!cmsys::SystemTools::FileIsFullPath(path)) { path = std::string(this->GeneratorTarget->Target->GetMakefile() ->GetCurrentSourceDirectory()) + "/" + path; } - this->ConvertToWindowsSlash(path); + ConvertToWindowsSlash(path); hintReferences.push_back(HintReference(name, path)); } } } if (!references.empty() || !hintReferences.empty()) { this->WriteString("<ItemGroup>\n", 1); - for (std::vector<std::string>::iterator ri = references.begin(); - ri != references.end(); ++ri) { + for (std::string const& ri : references) { // if the entry from VS_DOTNET_REFERENCES is an existing file, generate // a new hint-reference and name it from the filename - if (cmsys::SystemTools::FileExists(*ri, true)) { - std::string name = - cmsys::SystemTools::GetFilenameWithoutExtension(*ri); - std::string path = *ri; - this->ConvertToWindowsSlash(path); + if (cmsys::SystemTools::FileExists(ri, true)) { + std::string name = cmsys::SystemTools::GetFilenameWithoutExtension(ri); + std::string path = ri; + ConvertToWindowsSlash(path); hintReferences.push_back(HintReference(name, path)); } else { - this->WriteDotNetReference(*ri, ""); + this->WriteDotNetReference(ri, ""); } } - for (std::vector<std::pair<std::string, std::string>>::const_iterator i = - hintReferences.begin(); - i != hintReferences.end(); ++i) { - this->WriteDotNetReference(i->first, i->second); + for (const auto& i : hintReferences) { + this->WriteDotNetReference(i.first, i.second); } this->WriteString("</ItemGroup>\n", 1); } @@ -689,22 +670,19 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReferenceCustomTags( typedef std::map<std::string, std::string> CustomTags; CustomTags tags; cmPropertyMap const& props = this->GeneratorTarget->Target->GetProperties(); - for (cmPropertyMap::const_iterator i = props.begin(); i != props.end(); - ++i) { - if (i->first.find(refPropFullPrefix) == 0) { - std::string refTag = i->first.substr(refPropFullPrefix.length()); - std::string refVal = i->second.GetValue(); + for (const auto& i : props) { + if (i.first.find(refPropFullPrefix) == 0) { + std::string refTag = i.first.substr(refPropFullPrefix.length()); + std::string refVal = i.second.GetValue(); if (!refTag.empty() && !refVal.empty()) { tags[refTag] = refVal; } } } - for (CustomTags::const_iterator tag = tags.begin(); tag != tags.end(); - ++tag) { + for (auto const& tag : tags) { this->WriteString("<", 3); - (*this->BuildFileStream) << tag->first << ">" - << cmVS10EscapeXML(tag->second) << "</" - << tag->first << ">\n"; + (*this->BuildFileStream) << tag.first << ">" << cmVS10EscapeXML(tag.second) + << "</" << tag.first << ">\n"; } } @@ -715,13 +693,11 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup() if (!resxObjs.empty()) { this->WriteString("<ItemGroup>\n", 1); std::string srcDir = this->Makefile->GetCurrentSourceDirectory(); - this->ConvertToWindowsSlash(srcDir); - for (std::vector<cmSourceFile const*>::const_iterator oi = - resxObjs.begin(); - oi != resxObjs.end(); ++oi) { - std::string obj = (*oi)->GetFullPath(); + ConvertToWindowsSlash(srcDir); + for (cmSourceFile const* oi : resxObjs) { + std::string obj = oi->GetFullPath(); this->WriteString("<EmbeddedResource Include=\"", 2); - this->ConvertToWindowsSlash(obj); + ConvertToWindowsSlash(obj); bool useRelativePath = false; if (this->ProjectType == csproj && this->InSourceBuild) { // If we do an in-source build and the resource file is in a @@ -730,7 +706,7 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup() // visual studio does not show the file in the IDE. Sorry. if (obj.find(srcDir) == 0) { obj = this->ConvertPath(obj, true); - this->ConvertToWindowsSlash(obj); + ConvertToWindowsSlash(obj); useRelativePath = true; } } @@ -741,10 +717,8 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup() std::string hFileName = obj.substr(0, obj.find_last_of(".")) + ".h"; (*this->BuildFileStream) << hFileName << "</DependentUpon>\n"; - for (std::vector<std::string>::const_iterator i = - this->Configurations.begin(); - i != this->Configurations.end(); ++i) { - this->WritePlatformConfigTag("LogicalName", *i, 3); + for (std::string const& i : this->Configurations) { + this->WritePlatformConfigTag("LogicalName", i, 3); if (this->GeneratorTarget->GetProperty("VS_GLOBAL_ROOTNAMESPACE") || // Handle variant of VS_GLOBAL_<variable> for RootNamespace. this->GeneratorTarget->GetProperty("VS_GLOBAL_RootNamespace")) { @@ -756,7 +730,7 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup() } } else { std::string binDir = this->Makefile->GetCurrentBinaryDirectory(); - this->ConvertToWindowsSlash(binDir); + ConvertToWindowsSlash(binDir); // If the resource was NOT added using a relative path (which should // be the default), we have to provide a link here if (!useRelativePath) { @@ -775,13 +749,12 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup() } // Determine if this is a generated resource from a .Designer.cs file std::string designerResource = - cmSystemTools::GetFilenamePath((*oi)->GetFullPath()) + "/" + - cmSystemTools::GetFilenameWithoutLastExtension( - (*oi)->GetFullPath()) + + cmSystemTools::GetFilenamePath(oi->GetFullPath()) + "/" + + cmSystemTools::GetFilenameWithoutLastExtension(oi->GetFullPath()) + ".Designer.cs"; if (cmsys::SystemTools::FileExists(designerResource)) { std::string generator = "PublicResXFileCodeGenerator"; - if (const char* g = (*oi)->GetProperty("VS_RESOURCE_GENERATOR")) { + if (const char* g = oi->GetProperty("VS_RESOURCE_GENERATOR")) { generator = g; } if (!generator.empty()) { @@ -796,20 +769,19 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup() designerResource = cmsys::SystemTools::GetFilenameName(designerResource); } - this->ConvertToWindowsSlash(designerResource); + ConvertToWindowsSlash(designerResource); this->WriteString("<LastGenOutput>", 3); (*this->BuildFileStream) << designerResource << "</LastGenOutput>\n"; } } - const cmPropertyMap& props = (*oi)->GetProperties(); - for (cmPropertyMap::const_iterator p = props.begin(); p != props.end(); - ++p) { + const cmPropertyMap& props = oi->GetProperties(); + for (const auto& p : props) { static const std::string propNamePrefix = "VS_CSHARP_"; - if (p->first.find(propNamePrefix) == 0) { - std::string tagName = p->first.substr(propNamePrefix.length()); + if (p.first.find(propNamePrefix) == 0) { + std::string tagName = p.first.substr(propNamePrefix.length()); if (!tagName.empty()) { - std::string value = props.GetPropertyValue(p->first); + std::string value = props.GetPropertyValue(p.first); if (!value.empty()) { this->WriteString("<", 3); (*this->BuildFileStream) << tagName << ">"; @@ -833,19 +805,17 @@ void cmVisualStudio10TargetGenerator::WriteXamlFilesGroup() this->GeneratorTarget->GetXamlSources(xamlObjs, ""); if (!xamlObjs.empty()) { this->WriteString("<ItemGroup>\n", 1); - for (std::vector<cmSourceFile const*>::const_iterator oi = - xamlObjs.begin(); - oi != xamlObjs.end(); ++oi) { - std::string obj = (*oi)->GetFullPath(); + for (cmSourceFile const* oi : xamlObjs) { + std::string obj = oi->GetFullPath(); std::string xamlType; - const char* xamlTypeProperty = (*oi)->GetProperty("VS_XAML_TYPE"); + const char* xamlTypeProperty = oi->GetProperty("VS_XAML_TYPE"); if (xamlTypeProperty) { xamlType = xamlTypeProperty; } else { xamlType = "Page"; } - this->WriteSource(xamlType, *oi, ">\n"); + this->WriteSource(xamlType, oi, ">\n"); if (this->ProjectType == csproj && !this->InSourceBuild) { // add <Link> tag to written XAML source if necessary const std::string srcDir = this->Makefile->GetCurrentSourceDirectory(); @@ -859,7 +829,7 @@ void cmVisualStudio10TargetGenerator::WriteXamlFilesGroup() link = cmsys::SystemTools::GetFilenameName(obj); } if (!link.empty()) { - this->ConvertToWindowsSlash(link); + ConvertToWindowsSlash(link); this->WriteString("<Link>", 3); (*this->BuildFileStream) << link << "</Link>\n"; } @@ -1087,7 +1057,7 @@ void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValuesManaged( } std::string outDir = this->GeneratorTarget->GetDirectory(config) + "/"; - this->ConvertToWindowsSlash(outDir); + ConvertToWindowsSlash(outDir); this->WriteString("<OutputPath>", 2); (*this->BuildFileStream) << cmVS10EscapeXML(outDir) << "</OutputPath>\n"; @@ -1174,6 +1144,15 @@ void cmVisualStudio10TargetGenerator::WriteCustomCommands() si != customCommands.end(); ++si) { this->WriteCustomCommand(*si); } + + // Add CMakeLists.txt file with rule to re-run CMake for user convenience. + if (this->GeneratorTarget->GetType() != cmStateEnums::GLOBAL_TARGET && + this->GeneratorTarget->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET) { + if (cmSourceFile const* sf = + this->LocalGenerator->CreateVCProjBuildRule()) { + this->WriteCustomCommand(sf); + } + } } void cmVisualStudio10TargetGenerator::WriteCustomCommand( @@ -1258,7 +1237,7 @@ void cmVisualStudio10TargetGenerator::WriteCustomRule( d != ccg.GetDepends().end(); ++d) { std::string dep; if (this->LocalGenerator->GetRealDependency(*d, *i, dep)) { - this->ConvertToWindowsSlash(dep); + ConvertToWindowsSlash(dep); inputs << ";" << cmVS10EscapeXML(dep); } } @@ -1268,7 +1247,7 @@ void cmVisualStudio10TargetGenerator::WriteCustomRule( for (std::vector<std::string>::const_iterator o = ccg.GetOutputs().begin(); o != ccg.GetOutputs().end(); ++o) { std::string out = *o; - this->ConvertToWindowsSlash(out); + ConvertToWindowsSlash(out); outputs << sep << cmVS10EscapeXML(out); sep = ";"; } @@ -1346,7 +1325,7 @@ std::string cmVisualStudio10TargetGenerator::ConvertPath( : path.c_str(); } -void cmVisualStudio10TargetGenerator::ConvertToWindowsSlash(std::string& s) +static void ConvertToWindowsSlash(std::string& s) { // first convert all of the slashes std::string::size_type pos = 0; @@ -1373,7 +1352,7 @@ void cmVisualStudio10TargetGenerator::WriteGroups() si != sources.end(); ++si) { std::string const& source = si->Source->GetFullPath(); cmSourceGroup* sourceGroup = - this->Makefile->FindSourceGroup(source.c_str(), sourceGroups); + this->Makefile->FindSourceGroup(source, sourceGroups); groupsUsed.insert(sourceGroup); } @@ -1383,7 +1362,8 @@ void cmVisualStudio10TargetGenerator::WriteGroups() std::string path = this->LocalGenerator->GetCurrentBinaryDirectory(); path += "/"; path += this->Name; - path += computeProjectFileExtension(this->GeneratorTarget); + path += computeProjectFileExtension(this->GeneratorTarget, + *this->Configurations.begin()); path += ".filters"; cmGeneratedFileStream fout(path.c_str()); fout.SetCopyIfDifferent(true); @@ -1410,30 +1390,28 @@ void cmVisualStudio10TargetGenerator::WriteGroups() // Added files are images and the manifest. if (!this->AddedFiles.empty()) { this->WriteString("<ItemGroup>\n", 1); - for (std::vector<std::string>::const_iterator oi = - this->AddedFiles.begin(); - oi != this->AddedFiles.end(); ++oi) { + for (std::string const& oi : this->AddedFiles) { std::string fileName = - cmSystemTools::LowerCase(cmSystemTools::GetFilenameName(*oi)); + cmSystemTools::LowerCase(cmSystemTools::GetFilenameName(oi)); if (fileName == "wmappmanifest.xml") { this->WriteString("<XML Include=\"", 2); - (*this->BuildFileStream) << *oi << "\">\n"; + (*this->BuildFileStream) << oi << "\">\n"; this->WriteString("<Filter>Resource Files</Filter>\n", 3); this->WriteString("</XML>\n", 2); } else if (cmSystemTools::GetFilenameExtension(fileName) == ".appxmanifest") { this->WriteString("<AppxManifest Include=\"", 2); - (*this->BuildFileStream) << *oi << "\">\n"; + (*this->BuildFileStream) << oi << "\">\n"; this->WriteString("<Filter>Resource Files</Filter>\n", 3); this->WriteString("</AppxManifest>\n", 2); } else if (cmSystemTools::GetFilenameExtension(fileName) == ".pfx") { this->WriteString("<None Include=\"", 2); - (*this->BuildFileStream) << *oi << "\">\n"; + (*this->BuildFileStream) << oi << "\">\n"; this->WriteString("<Filter>Resource Files</Filter>\n", 3); this->WriteString("</None>\n", 2); } else { this->WriteString("<Image Include=\"", 2); - (*this->BuildFileStream) << *oi << "\">\n"; + (*this->BuildFileStream) << oi << "\">\n"; this->WriteString("<Filter>Resource Files</Filter>\n", 3); this->WriteString("</Image>\n", 2); } @@ -1445,12 +1423,10 @@ void cmVisualStudio10TargetGenerator::WriteGroups() this->GeneratorTarget->GetResxSources(resxObjs, ""); if (!resxObjs.empty()) { this->WriteString("<ItemGroup>\n", 1); - for (std::vector<cmSourceFile const*>::const_iterator oi = - resxObjs.begin(); - oi != resxObjs.end(); ++oi) { - std::string obj = (*oi)->GetFullPath(); + for (cmSourceFile const* oi : resxObjs) { + std::string obj = oi->GetFullPath(); this->WriteString("<EmbeddedResource Include=\"", 2); - this->ConvertToWindowsSlash(obj); + ConvertToWindowsSlash(obj); (*this->BuildFileStream) << cmVS10EscapeXML(obj) << "\">\n"; this->WriteString("<Filter>Resource Files</Filter>\n", 3); this->WriteString("</EmbeddedResource>\n", 2); @@ -1459,11 +1435,14 @@ void cmVisualStudio10TargetGenerator::WriteGroups() } this->WriteString("<ItemGroup>\n", 1); - for (std::set<cmSourceGroup*>::iterator g = groupsUsed.begin(); - g != groupsUsed.end(); ++g) { - cmSourceGroup* sg = *g; - const char* name = sg->GetFullName(); - if (strlen(name) != 0) { + std::vector<cmSourceGroup*> groupsVec(groupsUsed.begin(), groupsUsed.end()); + std::sort(groupsVec.begin(), groupsVec.end(), + [](cmSourceGroup* l, cmSourceGroup* r) { + return l->GetFullName() < r->GetFullName(); + }); + for (cmSourceGroup* sg : groupsVec) { + std::string const& name = sg->GetFullName(); + if (!name.empty()) { this->WriteString("<Filter Include=\"", 2); (*this->BuildFileStream) << name << "\">\n"; std::string guidName = "SG_Filter_"; @@ -1504,16 +1483,15 @@ void cmVisualStudio10TargetGenerator::AddMissingSourceGroups( std::set<cmSourceGroup*>& groupsUsed, const std::vector<cmSourceGroup>& allGroups) { - for (std::vector<cmSourceGroup>::const_iterator current = allGroups.begin(); - current != allGroups.end(); ++current) { - std::vector<cmSourceGroup> const& children = current->GetGroupChildren(); + for (cmSourceGroup const& current : allGroups) { + std::vector<cmSourceGroup> const& children = current.GetGroupChildren(); if (children.empty()) { continue; // the group is really empty } this->AddMissingSourceGroups(groupsUsed, children); - cmSourceGroup* current_ptr = const_cast<cmSourceGroup*>(&(*current)); + cmSourceGroup* current_ptr = const_cast<cmSourceGroup*>(¤t); if (groupsUsed.find(current_ptr) != groupsUsed.end()) { continue; // group has already been added to set } @@ -1542,18 +1520,17 @@ void cmVisualStudio10TargetGenerator::WriteGroupSources( std::vector<cmSourceGroup>& sourceGroups) { this->WriteString("<ItemGroup>\n", 1); - for (ToolSources::const_iterator s = sources.begin(); s != sources.end(); - ++s) { - cmSourceFile const* sf = s->SourceFile; + for (ToolSource const& s : sources) { + cmSourceFile const* sf = s.SourceFile; std::string const& source = sf->GetFullPath(); cmSourceGroup* sourceGroup = - this->Makefile->FindSourceGroup(source.c_str(), sourceGroups); - const char* filter = sourceGroup->GetFullName(); + this->Makefile->FindSourceGroup(source, sourceGroups); + std::string const& filter = sourceGroup->GetFullName(); this->WriteString("<", 2); - std::string path = this->ConvertPath(source, s->RelativePath); - this->ConvertToWindowsSlash(path); + std::string path = this->ConvertPath(source, s.RelativePath); + ConvertToWindowsSlash(path); (*this->BuildFileStream) << name << " Include=\"" << cmVS10EscapeXML(path); - if (strlen(filter)) { + if (!filter.empty()) { (*this->BuildFileStream) << "\">\n"; this->WriteString("<Filter>", 3); (*this->BuildFileStream) << filter << "</Filter>\n"; @@ -1592,6 +1569,8 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf) std::string shaderEntryPoint; std::string shaderModel; std::string shaderAdditionalFlags; + std::string shaderDisableOptimizations; + std::string shaderEnableDebug; std::string outputHeaderFile; std::string variableName; std::string settingsGenerator; @@ -1622,7 +1601,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf) sourceLink = cmsys::SystemTools::GetFilenameName(fullFileName); } if (!sourceLink.empty()) { - this->ConvertToWindowsSlash(sourceLink); + ConvertToWindowsSlash(sourceLink); } } } @@ -1658,6 +1637,16 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf) shaderAdditionalFlags = saf; toolHasSettings = true; } + // Figure out if debug information should be generated + if (const char* sed = sf->GetProperty("VS_SHADER_ENABLE_DEBUG")) { + shaderEnableDebug = cmSystemTools::IsOn(sed) ? "true" : "false"; + toolHasSettings = true; + } + // Figure out if optimizations should be disabled + if (const char* sdo = sf->GetProperty("VS_SHADER_DISABLE_OPTIMIZATIONS")) { + shaderDisableOptimizations = cmSystemTools::IsOn(sdo) ? "true" : "false"; + toolHasSettings = true; + } } else if (ext == "jpg" || ext == "png") { tool = "Image"; } else if (ext == "resw") { @@ -1667,12 +1656,8 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf) } else if (ext == "natvis") { tool = "Natvis"; } else if (ext == "settings") { - // remove path to current source dir (if files are in current source dir) - if (!sourceLink.empty()) { - settingsLastGenOutput = sourceLink; - } else { - settingsLastGenOutput = sf->GetFullPath(); - } + settingsLastGenOutput = + cmsys::SystemTools::GetFilenameName(sf->GetFullPath()); std::size_t pos = settingsLastGenOutput.find(".settings"); settingsLastGenOutput.replace(pos, 9, ".Designer.cs"); settingsGenerator = "SettingsSingleFileGenerator"; @@ -1800,6 +1785,16 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf) this->WriteString("</VariableName>\n", 0); } } + if (!shaderEnableDebug.empty()) { + this->WriteString("<EnableDebuggingInformation>", 3); + (*this->BuildFileStream) << cmVS10EscapeXML(shaderEnableDebug) + << "</EnableDebuggingInformation>\n"; + } + if (!shaderDisableOptimizations.empty()) { + this->WriteString("<DisableOptimizations>", 3); + (*this->BuildFileStream) << cmVS10EscapeXML(shaderDisableOptimizations) + << "</DisableOptimizations>\n"; + } if (!shaderAdditionalFlags.empty()) { this->WriteString("<AdditionalOptions>", 3); (*this->BuildFileStream) << cmVS10EscapeXML(shaderAdditionalFlags) @@ -1878,7 +1873,7 @@ void cmVisualStudio10TargetGenerator::WriteSource(std::string const& tool, this->GlobalGenerator->PathTooLong(this->GeneratorTarget, sf, sourceRel); } } - this->ConvertToWindowsSlash(sourceFile); + ConvertToWindowsSlash(sourceFile); this->WriteString("<", 2); (*this->BuildFileStream) << tool << " Include=\"" << cmVS10EscapeXML(sourceFile) << "\"" @@ -1903,11 +1898,9 @@ void cmVisualStudio10TargetGenerator::WriteAllSources() std::vector<cmGeneratorTarget::AllConfigSource> const& sources = this->GeneratorTarget->GetAllConfigSources(); - for (std::vector<cmGeneratorTarget::AllConfigSource>::const_iterator si = - sources.begin(); - si != sources.end(); ++si) { + for (cmGeneratorTarget::AllConfigSource const& si : sources) { std::string tool; - switch (si->Kind) { + switch (si.Kind) { case cmGeneratorTarget::SourceKindAppManifest: tool = "AppxManifest"; break; @@ -1926,17 +1919,17 @@ void cmVisualStudio10TargetGenerator::WriteAllSources() // then vs10 will use it in the build, and we have to list it as // None instead of Object. std::vector<cmSourceFile*> const* d = - this->GeneratorTarget->GetSourceDepends(si->Source); + this->GeneratorTarget->GetSourceDepends(si.Source); if (d && !d->empty()) { tool = "None"; } } break; case cmGeneratorTarget::SourceKindExtra: - this->WriteExtraSource(si->Source); + this->WriteExtraSource(si.Source); break; case cmGeneratorTarget::SourceKindHeader: - this->WriteHeaderSource(si->Source); + this->WriteHeaderSource(si.Source); break; case cmGeneratorTarget::SourceKindIDL: tool = "Midl"; @@ -1948,7 +1941,7 @@ void cmVisualStudio10TargetGenerator::WriteAllSources() tool = "None"; break; case cmGeneratorTarget::SourceKindObjectSource: { - const std::string& lang = si->Source->GetLanguage(); + const std::string& lang = si.Source->GetLanguage(); if (lang == "C" || lang == "CXX") { tool = "ClCompile"; } else if (lang == "ASM_MASM" && @@ -1977,16 +1970,16 @@ 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> 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) { + if (si.Kind == cmGeneratorTarget::SourceKindObjectSource) { // FIXME: refactor generation to avoid tracking XML syntax state. - this->WriteSource(tool, si->Source, " "); - bool have_nested = this->OutputSourceSpecificFlags(si->Source); + this->WriteSource(tool, si.Source, ""); + bool have_nested = this->OutputSourceSpecificFlags(si.Source); if (!exclude_configs.empty()) { if (!have_nested) { (*this->BuildFileStream) << ">\n"; @@ -2001,12 +1994,12 @@ void cmVisualStudio10TargetGenerator::WriteAllSources() (*this->BuildFileStream) << " />\n"; } } else if (!exclude_configs.empty()) { - this->WriteSource(tool, si->Source, ">\n"); + this->WriteSource(tool, si.Source, ">\n"); this->WriteExcludeFromBuild(exclude_configs); this->WriteString("</", 2); (*this->BuildFileStream) << tool << ">\n"; } else { - this->WriteSource(tool, si->Source); + this->WriteSource(tool, si.Source); } } } @@ -2029,17 +2022,32 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( } std::string flags; bool configDependentFlags = false; + std::string options; + bool configDependentOptions = false; std::string defines; + bool configDependentDefines = false; + std::string includes; + bool configDependentIncludes = false; if (const char* cflags = sf.GetProperty("COMPILE_FLAGS")) { - - if (cmGeneratorExpression::Find(cflags) != std::string::npos) { - configDependentFlags = true; - } + configDependentFlags = + cmGeneratorExpression::Find(cflags) != std::string::npos; flags += cflags; } + if (const char* coptions = sf.GetProperty("COMPILE_OPTIONS")) { + configDependentOptions = + cmGeneratorExpression::Find(coptions) != std::string::npos; + options += coptions; + } if (const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS")) { + configDependentDefines = + cmGeneratorExpression::Find(cdefs) != std::string::npos; defines += cdefs; } + if (const char* cincludes = sf.GetProperty("INCLUDE_DIRECTORIES")) { + configDependentIncludes = + cmGeneratorExpression::Find(cincludes) != std::string::npos; + includes += cincludes; + } std::string lang = this->GlobalGenerator->GetLanguageFromExtension(sf.GetExtension().c_str()); std::string sourceLang = this->LocalGenerator->GetSourceFileLanguage(sf); @@ -2072,14 +2080,18 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( (*this->BuildFileStream) << firstString; firstString = ""; hasFlags = true; - this->WriteString("<ObjectFileName>", 3); - (*this->BuildFileStream) << "$(IntDir)/" << objectName - << "</ObjectFileName>\n"; + if (lang == "CUDA") { + this->WriteString("<CompileOut>", 3); + (*this->BuildFileStream) << "$(IntDir)/" << objectName + << "</CompileOut>\n"; + } else { + this->WriteString("<ObjectFileName>", 3); + (*this->BuildFileStream) << "$(IntDir)/" << objectName + << "</ObjectFileName>\n"; + } } - for (std::vector<std::string>::const_iterator config = - this->Configurations.begin(); - config != this->Configurations.end(); ++config) { - std::string configUpper = cmSystemTools::UpperCase(*config); + for (std::string const& config : this->Configurations) { + std::string configUpper = cmSystemTools::UpperCase(config); std::string configDefines = defines; std::string defPropName = "COMPILE_DEFINITIONS_"; defPropName += configUpper; @@ -2087,12 +2099,14 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( if (!configDefines.empty()) { configDefines += ";"; } + configDependentDefines |= + cmGeneratorExpression::Find(ccdefs) != std::string::npos; configDefines += ccdefs; } // if we have flags or defines for this config then // use them - if (!flags.empty() || configDependentFlags || !configDefines.empty() || - compileAs || noWinRT) { + if (!flags.empty() || !options.empty() || !configDefines.empty() || + !includes.empty() || compileAs || noWinRT) { (*this->BuildFileStream) << firstString; firstString = ""; // only do firstString once hasFlags = true; @@ -2113,6 +2127,9 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( } else if (srclang == "CSharp") { flagtable = gg->GetCSharpFlagTable(); } + cmGeneratorExpressionInterpreter genexInterpreter( + this->LocalGenerator, this->GeneratorTarget, config, + this->GeneratorTarget->GetName(), lang); cmVisualStudioGeneratorOptions clOptions( this->LocalGenerator, cmVisualStudioGeneratorOptions::Compiler, flagtable, 0, this); @@ -2123,25 +2140,45 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( clOptions.AddFlag("CompileAsWinRT", "false"); } if (configDependentFlags) { - cmGeneratorExpression ge; - std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(flags); - std::string evaluatedFlags = cge->Evaluate( - this->LocalGenerator, *config, false, this->GeneratorTarget); - clOptions.Parse(evaluatedFlags.c_str()); + clOptions.Parse(genexInterpreter.Evaluate(flags, "COMPILE_FLAGS")); } else { clOptions.Parse(flags.c_str()); } - if (clOptions.HasFlag("AdditionalIncludeDirectories")) { - clOptions.AppendFlag("AdditionalIncludeDirectories", - "%(AdditionalIncludeDirectories)"); + if (!options.empty()) { + std::string expandedOptions; + if (configDependentOptions) { + this->LocalGenerator->AppendCompileOptions( + expandedOptions, + genexInterpreter.Evaluate(options, "COMPILE_OPTIONS")); + } else { + this->LocalGenerator->AppendCompileOptions(expandedOptions, options); + } + clOptions.Parse(expandedOptions.c_str()); } if (clOptions.HasFlag("DisableSpecificWarnings")) { clOptions.AppendFlag("DisableSpecificWarnings", "%(DisableSpecificWarnings)"); } - clOptions.AddDefines(configDefines.c_str()); - clOptions.SetConfiguration((*config).c_str()); + if (configDependentDefines) { + clOptions.AddDefines( + genexInterpreter.Evaluate(configDefines, "COMPILE_DEFINITIONS")); + } else { + clOptions.AddDefines(configDefines.c_str()); + } + std::vector<std::string> includeList; + if (configDependentIncludes) { + this->LocalGenerator->AppendIncludeDirectories( + includeList, + genexInterpreter.Evaluate(includes, "INCLUDE_DIRECTORIES"), *source); + } else { + this->LocalGenerator->AppendIncludeDirectories(includeList, includes, + *source); + } + clOptions.AddIncludes(includeList); + clOptions.SetConfiguration(config.c_str()); clOptions.PrependInheritedString("AdditionalOptions"); + clOptions.OutputAdditionalIncludeDirectories(*this->BuildFileStream, + " ", "\n", lang); clOptions.OutputFlagMap(*this->BuildFileStream, " "); clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ", "\n", lang); @@ -2182,12 +2219,11 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( 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) { + for (size_t ci : exclude_configs) { this->WriteString("", 3); (*this->BuildFileStream) << "<ExcludedFromBuild Condition=\"'$(Configuration)|$(Platform)'=='" - << cmVS10EscapeXML(this->Configurations[*ci]) << "|" + << cmVS10EscapeXML(this->Configurations[ci]) << "|" << cmVS10EscapeXML(this->Platform) << "'\">true</ExcludedFromBuild>\n"; } } @@ -2206,11 +2242,9 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions() this->WriteString("<_ProjectFileVersion>10.0.20506.1" "</_ProjectFileVersion>\n", 2); - for (std::vector<std::string>::const_iterator config = - this->Configurations.begin(); - config != this->Configurations.end(); ++config) { + for (std::string const& config : this->Configurations) { if (ttype >= cmStateEnums::UTILITY) { - this->WritePlatformConfigTag("IntDir", *config, 2); + this->WritePlatformConfigTag("IntDir", config, 2); *this->BuildFileStream << "$(Platform)\\$(Configuration)\\$(ProjectName)\\" << "</IntDir>\n"; @@ -2218,7 +2252,7 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions() std::string intermediateDir = this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget); intermediateDir += "/"; - intermediateDir += *config; + intermediateDir += config; intermediateDir += "/"; std::string outDir; std::string targetNameFull; @@ -2227,22 +2261,22 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions() targetNameFull = this->GeneratorTarget->GetName(); targetNameFull += ".lib"; } else { - outDir = this->GeneratorTarget->GetDirectory(*config) + "/"; - targetNameFull = this->GeneratorTarget->GetFullName(*config); + outDir = this->GeneratorTarget->GetDirectory(config) + "/"; + targetNameFull = this->GeneratorTarget->GetFullName(config); } - this->ConvertToWindowsSlash(intermediateDir); - this->ConvertToWindowsSlash(outDir); + ConvertToWindowsSlash(intermediateDir); + ConvertToWindowsSlash(outDir); - this->WritePlatformConfigTag("OutDir", *config, 2); + this->WritePlatformConfigTag("OutDir", config, 2); *this->BuildFileStream << cmVS10EscapeXML(outDir) << "</OutDir>\n"; - this->WritePlatformConfigTag("IntDir", *config, 2); + this->WritePlatformConfigTag("IntDir", config, 2); *this->BuildFileStream << cmVS10EscapeXML(intermediateDir) << "</IntDir>\n"; if (const char* workingDir = this->GeneratorTarget->GetProperty( "VS_DEBUGGER_WORKING_DIRECTORY")) { - this->WritePlatformConfigTag("LocalDebuggerWorkingDirectory", *config, + this->WritePlatformConfigTag("LocalDebuggerWorkingDirectory", config, 2); *this->BuildFileStream << cmVS10EscapeXML(workingDir) << "</LocalDebuggerWorkingDirectory>\n"; @@ -2250,7 +2284,7 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions() std::string name = cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull); - this->WritePlatformConfigTag("TargetName", *config, 2); + this->WritePlatformConfigTag("TargetName", config, 2); *this->BuildFileStream << cmVS10EscapeXML(name) << "</TargetName>\n"; std::string ext = @@ -2260,10 +2294,10 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions() // A single "." appears to be treated as an empty extension. ext = "."; } - this->WritePlatformConfigTag("TargetExt", *config, 2); + this->WritePlatformConfigTag("TargetExt", config, 2); *this->BuildFileStream << cmVS10EscapeXML(ext) << "</TargetExt>\n"; - this->OutputLinkIncremental(*config); + this->OutputLinkIncremental(config); } } this->WriteString("</PropertyGroup>\n", 1); @@ -2311,12 +2345,22 @@ void cmVisualStudio10TargetGenerator::OutputLinkIncremental( } } +std::vector<std::string> cmVisualStudio10TargetGenerator::GetIncludes( + std::string const& config, std::string const& lang) const +{ + std::vector<std::string> includes; + this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget, + lang, config); + for (std::string& i : includes) { + ConvertToWindowsSlash(i); + } + return includes; +} + bool cmVisualStudio10TargetGenerator::ComputeClOptions() { - for (std::vector<std::string>::const_iterator i = - this->Configurations.begin(); - i != this->Configurations.end(); ++i) { - if (!this->ComputeClOptions(*i)) { + for (std::string const& i : this->Configurations) { + if (!this->ComputeClOptions(i)) { return false; } } @@ -2359,20 +2403,21 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( // Choose a language whose flags to use for ClCompile. static const char* clLangs[] = { "CXX", "C", "Fortran", "CSharp" }; std::string langForClCompile; - if (std::find(cmArrayBegin(clLangs), cmArrayEnd(clLangs), linkLanguage) != - cmArrayEnd(clLangs)) { + if (std::find(cm::cbegin(clLangs), cm::cend(clLangs), linkLanguage) != + cm::cend(clLangs)) { langForClCompile = linkLanguage; } else { std::set<std::string> languages; this->GeneratorTarget->GetLanguages(languages, configName); - for (const char* const* l = cmArrayBegin(clLangs); - l != cmArrayEnd(clLangs); ++l) { + for (const char* const* l = cm::cbegin(clLangs); l != cm::cend(clLangs); + ++l) { if (languages.find(*l) != languages.end()) { langForClCompile = *l; break; } } } + this->LangForClCompile = langForClCompile; if (!langForClCompile.empty()) { std::string baseFlagVar = "CMAKE_"; baseFlagVar += langForClCompile; @@ -2408,7 +2453,7 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( clOptions.FixExceptionHandlingDefault(); clOptions.AddFlag("PrecompiledHeader", "NotUsing"); std::string asmLocation = configName + "/"; - clOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str()); + clOptions.AddFlag("AssemblerListingLocation", asmLocation); } } clOptions.Parse(flags.c_str()); @@ -2416,8 +2461,10 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( std::vector<std::string> targetDefines; switch (this->ProjectType) { case vcxproj: - this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName, - "CXX"); + if (!langForClCompile.empty()) { + this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName, + langForClCompile); + } break; case csproj: this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName, @@ -2425,6 +2472,13 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( break; } clOptions.AddDefines(targetDefines); + + // Get includes for this target + if (!this->LangForClCompile.empty()) { + clOptions.AddIncludes( + this->GetIncludes(configName, this->LangForClCompile)); + } + if (this->MSTools) { clOptions.SetVerboseMakefile( this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE")); @@ -2476,12 +2530,12 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( } } - this->ClOptions[configName] = pOptions.release(); + this->ClOptions[configName] = std::move(pOptions); return true; } void cmVisualStudio10TargetGenerator::WriteClOptions( - std::string const& configName, std::vector<std::string> const& includes) + std::string const& configName) { Options& clOptions = *(this->ClOptions[configName]); if (this->ProjectType == csproj) { @@ -2489,12 +2543,11 @@ void cmVisualStudio10TargetGenerator::WriteClOptions( } this->WriteString("<ClCompile>\n", 2); clOptions.PrependInheritedString("AdditionalOptions"); - clOptions.AppendFlag("AdditionalIncludeDirectories", includes); - clOptions.AppendFlag("AdditionalIncludeDirectories", - "%(AdditionalIncludeDirectories)"); + clOptions.OutputAdditionalIncludeDirectories( + *this->BuildFileStream, " ", "\n", this->LangForClCompile); clOptions.OutputFlagMap(*this->BuildFileStream, " "); clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ", - "\n", "CXX"); + "\n", this->LangForClCompile); if (this->NsightTegra) { if (const char* processMax = @@ -2518,17 +2571,18 @@ void cmVisualStudio10TargetGenerator::WriteClOptions( } // If not in debug mode, write the DebugInformationFormat field - // without value so PDBs don't get generated uselessly. + // without value so PDBs don't get generated uselessly. Each tag + // goes on its own line because Visual Studio corrects it this + // way when saving the project after CMake generates it. if (!clOptions.IsDebug()) { - this->WriteString("<DebugInformationFormat>" - "</DebugInformationFormat>\n", - 3); + this->WriteString("<DebugInformationFormat>\n", 3); + this->WriteString("</DebugInformationFormat>\n", 3); } // Specify the compiler program database file if configured. std::string pdb = this->GeneratorTarget->GetCompilePDBPath(configName); if (!pdb.empty()) { - this->ConvertToWindowsSlash(pdb); + ConvertToWindowsSlash(pdb); this->WriteString("<ProgramDataBaseFileName>", 3); *this->BuildFileStream << cmVS10EscapeXML(pdb) << "</ProgramDataBaseFileName>\n"; @@ -2540,10 +2594,8 @@ void cmVisualStudio10TargetGenerator::WriteClOptions( bool cmVisualStudio10TargetGenerator::ComputeRcOptions() { - for (std::vector<std::string>::const_iterator i = - this->Configurations.begin(); - i != this->Configurations.end(); ++i) { - if (!this->ComputeRcOptions(*i)) { + for (std::string const& i : this->Configurations) { + if (!this->ComputeRcOptions(i)) { return false; } } @@ -2572,12 +2624,15 @@ bool cmVisualStudio10TargetGenerator::ComputeRcOptions( Options& clOptions = *(this->ClOptions[configName]); rcOptions.AddDefines(clOptions.GetDefines()); - this->RcOptions[configName] = pOptions.release(); + // Get includes for this target + rcOptions.AddIncludes(this->GetIncludes(configName, "RC")); + + this->RcOptions[configName] = std::move(pOptions); return true; } void cmVisualStudio10TargetGenerator::WriteRCOptions( - std::string const& configName, std::vector<std::string> const& includes) + std::string const& configName) { if (!this->MSTools) { return; @@ -2587,9 +2642,8 @@ void cmVisualStudio10TargetGenerator::WriteRCOptions( Options& rcOptions = *(this->RcOptions[configName]); rcOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ", "\n", "RC"); - rcOptions.AppendFlag("AdditionalIncludeDirectories", includes); - rcOptions.AppendFlag("AdditionalIncludeDirectories", - "%(AdditionalIncludeDirectories)"); + rcOptions.OutputAdditionalIncludeDirectories(*this->BuildFileStream, + " ", "\n", "RC"); rcOptions.PrependInheritedString("AdditionalOptions"); rcOptions.OutputFlagMap(*this->BuildFileStream, " "); @@ -2601,10 +2655,8 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions() if (!this->GlobalGenerator->IsCudaEnabled()) { return true; } - for (std::vector<std::string>::const_iterator i = - this->Configurations.begin(); - i != this->Configurations.end(); ++i) { - if (!this->ComputeCudaOptions(*i)) { + for (std::string const& i : this->Configurations) { + if (!this->ComputeCudaOptions(i)) { return false; } } @@ -2638,6 +2690,18 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions( cudaOptions.Parse(defineFlags.c_str()); cudaOptions.ParseFinish(); + // If we haven't explicitly enabled GPU debug information + // explicitly disable it + if (!cudaOptions.HasFlag("GPUDebugInfo")) { + cudaOptions.AddFlag("GPUDebugInfo", "false"); + } + + // The extension on object libraries the CUDA gives isn't + // consistent with how MSVC generates object libraries for C+, so set + // the default to not have any extension + cudaOptions.AddFlag("CompileOut", "$(IntDir)%(Filename).obj"); + + bool notPtx = true; if (this->GeneratorTarget->GetPropertyAsBool("CUDA_SEPARABLE_COMPILATION")) { cudaOptions.AddFlag("GenerateRelocatableDeviceCode", "true"); } else if (this->GeneratorTarget->GetPropertyAsBool( @@ -2646,6 +2710,16 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions( // We drop the %(Extension) component as CMake expects all PTX files // to not have the source file extension at all cudaOptions.AddFlag("CompileOut", "$(IntDir)%(Filename).ptx"); + notPtx = false; + } + + if (notPtx && + cmSystemTools::VersionCompareGreaterEq( + "8.0", this->GlobalGenerator->GetPlatformToolsetCudaString())) { + // Explicitly state that we want this file to be treated as a + // CUDA file no matter what the file extensions is + // This is only needed for < CUDA 9 + cudaOptions.AppendFlagString("AdditionalOptions", "-x cu"); } // CUDA automatically passes the proper '--machine' flag to nvcc @@ -2688,12 +2762,15 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions( cudaOptions.AddDefine(exportMacro); } - this->CudaOptions[configName] = pOptions.release(); + // Get includes for this target + cudaOptions.AddIncludes(this->GetIncludes(configName, "CUDA")); + + this->CudaOptions[configName] = std::move(pOptions); return true; } void cmVisualStudio10TargetGenerator::WriteCudaOptions( - std::string const& configName, std::vector<std::string> const& includes) + std::string const& configName) { if (!this->MSTools || !this->GlobalGenerator->IsCudaEnabled()) { return; @@ -2701,8 +2778,8 @@ void cmVisualStudio10TargetGenerator::WriteCudaOptions( this->WriteString("<CudaCompile>\n", 2); Options& cudaOptions = *(this->CudaOptions[configName]); - cudaOptions.AppendFlag("Include", includes); - cudaOptions.AppendFlag("Include", "%(Include)"); + cudaOptions.OutputAdditionalIncludeDirectories(*this->BuildFileStream, + " ", "\n", "CUDA"); cudaOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ", "\n", "CUDA"); cudaOptions.PrependInheritedString("AdditionalOptions"); @@ -2716,10 +2793,8 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions() if (!this->GlobalGenerator->IsCudaEnabled()) { return true; } - for (std::vector<std::string>::const_iterator i = - this->Configurations.begin(); - i != this->Configurations.end(); ++i) { - if (!this->ComputeCudaLinkOptions(*i)) { + for (std::string const& i : this->Configurations) { + if (!this->ComputeCudaLinkOptions(i)) { return false; } } @@ -2761,7 +2836,7 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions( "-Wno-deprecated-gpu-targets"); } - this->CudaLinkOptions[configName] = pOptions.release(); + this->CudaLinkOptions[configName] = std::move(pOptions); return true; } @@ -2787,10 +2862,8 @@ bool cmVisualStudio10TargetGenerator::ComputeMasmOptions() if (!this->GlobalGenerator->IsMasmEnabled()) { return true; } - for (std::vector<std::string>::const_iterator i = - this->Configurations.begin(); - i != this->Configurations.end(); ++i) { - if (!this->ComputeMasmOptions(*i)) { + for (std::string const& i : this->Configurations) { + if (!this->ComputeMasmOptions(i)) { return false; } } @@ -2814,12 +2887,16 @@ bool cmVisualStudio10TargetGenerator::ComputeMasmOptions( std::string(this->Makefile->GetSafeDefinition(configFlagsVar)); masmOptions.Parse(flags.c_str()); - this->MasmOptions[configName] = pOptions.release(); + + // Get includes for this target + masmOptions.AddIncludes(this->GetIncludes(configName, "ASM_MASM")); + + this->MasmOptions[configName] = std::move(pOptions); return true; } void cmVisualStudio10TargetGenerator::WriteMasmOptions( - std::string const& configName, std::vector<std::string> const& includes) + std::string const& configName) { if (!this->MSTools || !this->GlobalGenerator->IsMasmEnabled()) { return; @@ -2832,8 +2909,8 @@ void cmVisualStudio10TargetGenerator::WriteMasmOptions( "\n", "ASM_MASM"); Options& masmOptions = *(this->MasmOptions[configName]); - masmOptions.AppendFlag("IncludePaths", includes); - masmOptions.AppendFlag("IncludePaths", "%(IncludePaths)"); + masmOptions.OutputAdditionalIncludeDirectories(*this->BuildFileStream, + " ", "\n", "ASM_MASM"); masmOptions.PrependInheritedString("AdditionalOptions"); masmOptions.OutputFlagMap(*this->BuildFileStream, " "); @@ -2845,10 +2922,8 @@ bool cmVisualStudio10TargetGenerator::ComputeNasmOptions() if (!this->GlobalGenerator->IsNasmEnabled()) { return true; } - for (std::vector<std::string>::const_iterator i = - this->Configurations.begin(); - i != this->Configurations.end(); ++i) { - if (!this->ComputeNasmOptions(*i)) { + for (std::string const& i : this->Configurations) { + if (!this->ComputeNasmOptions(i)) { return false; } } @@ -2873,25 +2948,27 @@ bool cmVisualStudio10TargetGenerator::ComputeNasmOptions( std::string(" ") + std::string(this->Makefile->GetSafeDefinition(configFlagsVar)); nasmOptions.Parse(flags.c_str()); - this->NasmOptions[configName] = pOptions.release(); + + // Get includes for this target + nasmOptions.AddIncludes(this->GetIncludes(configName, "ASM_NASM")); + + this->NasmOptions[configName] = std::move(pOptions); return true; } void cmVisualStudio10TargetGenerator::WriteNasmOptions( - std::string const& configName, std::vector<std::string> includes) + std::string const& configName) { if (!this->GlobalGenerator->IsNasmEnabled()) { return; } this->WriteString("<NASM>\n", 2); + std::vector<std::string> includes = + this->GetIncludes(configName, "ASM_NASM"); Options& nasmOptions = *(this->NasmOptions[configName]); - for (size_t i = 0; i < includes.size(); i++) { - includes[i] += "\\"; - } - - nasmOptions.AppendFlag("IncludePaths", includes); - nasmOptions.AppendFlag("IncludePaths", "%(IncludePaths)"); + nasmOptions.OutputAdditionalIncludeDirectories(*this->BuildFileStream, + " ", "\n", "ASM_NASM"); nasmOptions.OutputFlagMap(*this->BuildFileStream, " "); nasmOptions.PrependInheritedString("AdditionalOptions"); nasmOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ", @@ -2955,11 +3032,9 @@ void cmVisualStudio10TargetGenerator::WriteManifestOptions( if (!manifest_srcs.empty()) { this->WriteString("<Manifest>\n", 2); this->WriteString("<AdditionalManifestFiles>", 3); - for (std::vector<cmSourceFile const*>::const_iterator mi = - manifest_srcs.begin(); - mi != manifest_srcs.end(); ++mi) { - std::string m = this->ConvertPath((*mi)->GetFullPath(), false); - this->ConvertToWindowsSlash(m); + for (cmSourceFile const* mi : manifest_srcs) { + std::string m = this->ConvertPath(mi->GetFullPath(), false); + ConvertToWindowsSlash(m); (*this->BuildFileStream) << m << ";"; } (*this->BuildFileStream) << "</AdditionalManifestFiles>\n"; @@ -2976,12 +3051,10 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions( { std::vector<cmSourceFile const*> extraSources; this->GeneratorTarget->GetExtraSources(extraSources, ""); - for (std::vector<cmSourceFile const*>::const_iterator si = - extraSources.begin(); - si != extraSources.end(); ++si) { + for (cmSourceFile const* si : extraSources) { if ("androidmanifest.xml" == - cmSystemTools::LowerCase((*si)->GetLocation().GetName())) { - rootDir = (*si)->GetLocation().GetDirectory(); + cmSystemTools::LowerCase(si->GetLocation().GetName())) { + rootDir = si->GetLocation().GetDirectory(); break; } } @@ -2992,7 +3065,7 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions( std::string antBuildPath = rootDir; this->WriteString("<AntBuild>\n", 2); this->WriteString("<AntBuildPath>", 3); - this->ConvertToWindowsSlash(antBuildPath); + ConvertToWindowsSlash(antBuildPath); (*this->BuildFileStream) << cmVS10EscapeXML(antBuildPath) << "</AntBuildPath>\n"; } @@ -3079,7 +3152,7 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions( { std::string manifest_xml = rootDir + "/AndroidManifest.xml"; - this->ConvertToWindowsSlash(manifest_xml); + ConvertToWindowsSlash(manifest_xml); this->WriteString("<AndroidManifestLocation>", 3); (*this->BuildFileStream) << cmVS10EscapeXML(manifest_xml) << "</AndroidManifestLocation>\n"; @@ -3100,10 +3173,8 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions() if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE || this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY || this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) { - for (std::vector<std::string>::const_iterator i = - this->Configurations.begin(); - i != this->Configurations.end(); ++i) { - if (!this->ComputeLinkOptions(*i)) { + for (std::string const& i : this->Configurations) { + if (!this->ComputeLinkOptions(i)) { return false; } } @@ -3200,19 +3271,17 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( linkOptions.AddFlag("AdditionalDependencies", libVec); // Populate TargetsFileAndConfigsVec - for (std::vector<std::string>::iterator ti = vsTargetVec.begin(); - ti != vsTargetVec.end(); ++ti) { - this->AddTargetsFileAndConfigPair(*ti, config); + for (std::string const& ti : vsTargetVec) { + this->AddTargetsFileAndConfigPair(ti, config); } std::vector<std::string> const& ldirs = cli.GetDirectories(); std::vector<std::string> linkDirs; - for (std::vector<std::string>::const_iterator d = ldirs.begin(); - d != ldirs.end(); ++d) { + for (std::string const& d : ldirs) { // first just full path - linkDirs.push_back(*d); + linkDirs.push_back(d); // next path with configuration type Debug, Release, etc - linkDirs.push_back(*d + "/$(Configuration)"); + linkDirs.push_back(d + "/$(Configuration)"); } linkDirs.push_back("%(AdditionalLibraryDirectories)"); linkOptions.AddFlag("AdditionalLibraryDirectories", linkDirs); @@ -3275,8 +3344,8 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( imLib += "/"; imLib += targetNameImport; - linkOptions.AddFlag("ImportLibrary", imLib.c_str()); - linkOptions.AddFlag("ProgramDataBaseFile", pdb.c_str()); + linkOptions.AddFlag("ImportLibrary", imLib); + linkOptions.AddFlag("ProgramDataBaseFile", pdb); // A Windows Runtime component uses internal .NET metadata, // so does not have an import library. @@ -3297,7 +3366,7 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries", "ole32.lib"); } } else if (this->NsightTegra) { - linkOptions.AddFlag("SoName", targetNameSO.c_str()); + linkOptions.AddFlag("SoName", targetNameSO); } linkOptions.Parse(flags.c_str()); @@ -3325,17 +3394,15 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( } } - this->LinkOptions[config] = pOptions.release(); + this->LinkOptions[config] = std::move(pOptions); return true; } bool cmVisualStudio10TargetGenerator::ComputeLibOptions() { if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) { - for (std::vector<std::string>::const_iterator i = - this->Configurations.begin(); - i != this->Configurations.end(); ++i) { - if (!this->ComputeLibOptions(*i)) { + for (std::string const& i : this->Configurations) { + if (!this->ComputeLibOptions(i)) { return false; } } @@ -3360,11 +3427,11 @@ bool cmVisualStudio10TargetGenerator::ComputeLibOptions( const ItemVector& libs = cli.GetItems(); std::string currentBinDir = this->LocalGenerator->GetCurrentBinaryDirectory(); - for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) { - if (l->IsPath && cmVS10IsTargetsFile(l->Value)) { + for (cmComputeLinkInformation::Item const& l : libs) { + if (l.IsPath && cmVS10IsTargetsFile(l.Value)) { std::string path = - this->LocalGenerator->ConvertToRelativePath(currentBinDir, l->Value); - this->ConvertToWindowsSlash(path); + this->LocalGenerator->ConvertToRelativePath(currentBinDir, l.Value); + ConvertToWindowsSlash(path); this->AddTargetsFileAndConfigPair(path, config); } } @@ -3406,19 +3473,19 @@ void cmVisualStudio10TargetGenerator::AddLibraries( ItemVector const& libs = cli.GetItems(); std::string currentBinDir = this->LocalGenerator->GetCurrentBinaryDirectory(); - for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) { - if (l->IsPath) { + for (cmComputeLinkInformation::Item const& l : libs) { + if (l.IsPath) { std::string path = - this->LocalGenerator->ConvertToRelativePath(currentBinDir, l->Value); - this->ConvertToWindowsSlash(path); - if (cmVS10IsTargetsFile(l->Value)) { + this->LocalGenerator->ConvertToRelativePath(currentBinDir, l.Value); + ConvertToWindowsSlash(path); + if (cmVS10IsTargetsFile(l.Value)) { vsTargetVec.push_back(path); } else { libVec.push_back(path); } - } else if (!l->Target || - l->Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) { - libVec.push_back(l->Value); + } else if (!l.Target || + l.Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) { + libVec.push_back(l.Value); } } } @@ -3426,13 +3493,11 @@ void cmVisualStudio10TargetGenerator::AddLibraries( void cmVisualStudio10TargetGenerator::AddTargetsFileAndConfigPair( std::string const& targetsFile, std::string const& config) { - for (std::vector<TargetsFileAndConfigs>::iterator i = - this->TargetsFileAndConfigsVec.begin(); - i != this->TargetsFileAndConfigsVec.end(); ++i) { - if (cmSystemTools::ComparePath(targetsFile, i->File)) { - if (std::find(i->Configs.begin(), i->Configs.end(), config) == - i->Configs.end()) { - i->Configs.push_back(config); + for (TargetsFileAndConfigs& i : this->TargetsFileAndConfigsVec) { + if (cmSystemTools::ComparePath(targetsFile, i.File)) { + if (std::find(i.Configs.begin(), i.Configs.end(), config) == + i.Configs.end()) { + i.Configs.push_back(config); } return; } @@ -3444,7 +3509,7 @@ void cmVisualStudio10TargetGenerator::AddTargetsFileAndConfigPair( } void cmVisualStudio10TargetGenerator::WriteMidlOptions( - std::string const& /*config*/, std::vector<std::string> const& includes) + std::string const& configName) { if (!this->MSTools) { return; @@ -3470,9 +3535,10 @@ void cmVisualStudio10TargetGenerator::WriteMidlOptions( // on the CMake side? this->WriteString("<Midl>\n", 2); this->WriteString("<AdditionalIncludeDirectories>", 3); - for (std::vector<std::string>::const_iterator i = includes.begin(); - i != includes.end(); ++i) { - *this->BuildFileStream << cmVS10EscapeXML(*i) << ";"; + std::vector<std::string> const includes = + this->GetIncludes(configName, "MIDL"); + for (std::string const& i : includes) { + *this->BuildFileStream << cmVS10EscapeXML(i) << ";"; } this->WriteString("%(AdditionalIncludeDirectories)" "</AdditionalIncludeDirectories>\n", @@ -3494,44 +3560,35 @@ void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups() if (this->ProjectType == csproj) { return; } - for (std::vector<std::string>::const_iterator i = - this->Configurations.begin(); - i != this->Configurations.end(); ++i) { - std::vector<std::string> includes; - this->LocalGenerator->GetIncludeDirectories( - includes, this->GeneratorTarget, "C", *i); - for (std::vector<std::string>::iterator ii = includes.begin(); - ii != includes.end(); ++ii) { - this->ConvertToWindowsSlash(*ii); - } - this->WritePlatformConfigTag("ItemDefinitionGroup", *i, 1); + for (const auto& i : this->Configurations) { + this->WritePlatformConfigTag("ItemDefinitionGroup", i, 1); *this->BuildFileStream << "\n"; // output cl compile flags <ClCompile></ClCompile> if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) { - this->WriteClOptions(*i, includes); + this->WriteClOptions(i); // output rc compile flags <ResourceCompile></ResourceCompile> - this->WriteRCOptions(*i, includes); - this->WriteCudaOptions(*i, includes); - this->WriteMasmOptions(*i, includes); - this->WriteNasmOptions(*i, includes); + this->WriteRCOptions(i); + this->WriteCudaOptions(i); + this->WriteMasmOptions(i); + this->WriteNasmOptions(i); } // output midl flags <Midl></Midl> - this->WriteMidlOptions(*i, includes); + this->WriteMidlOptions(i); // write events if (this->ProjectType != csproj) { - this->WriteEvents(*i); + this->WriteEvents(i); } // output link flags <Link></Link> - this->WriteLinkOptions(*i); - this->WriteCudaLinkOptions(*i); + this->WriteLinkOptions(i); + this->WriteCudaLinkOptions(i); // output lib flags <Lib></Lib> - this->WriteLibOptions(*i); + this->WriteLibOptions(i); // output manifest flags <Manifest></Manifest> - this->WriteManifestOptions(*i); + this->WriteManifestOptions(i); if (this->NsightTegra && this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE && this->GeneratorTarget->GetPropertyAsBool("ANDROID_GUI")) { - this->WriteAntBuildOptions(*i); + this->WriteAntBuildOptions(i); } this->WriteString("</ItemDefinitionGroup>\n", 1); } @@ -3574,9 +3631,8 @@ void cmVisualStudio10TargetGenerator::WriteEvent( std::string script; const char* pre = ""; std::string comment; - for (std::vector<cmCustomCommand>::const_iterator i = commands.begin(); - i != commands.end(); ++i) { - cmCustomCommandGenerator ccg(*i, configName, this->LocalGenerator); + for (cmCustomCommand const& i : commands) { + cmCustomCommandGenerator ccg(i, configName, this->LocalGenerator); if (!ccg.HasOnlyEmptyCommandLines()) { comment += pre; comment += lg->ConstructComment(ccg); @@ -3616,9 +3672,8 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences() OrderedTargetDependSet; OrderedTargetDependSet depends(unordered, CMAKE_CHECK_BUILD_SYSTEM_TARGET); this->WriteString("<ItemGroup>\n", 1); - for (OrderedTargetDependSet::const_iterator i = depends.begin(); - i != depends.end(); ++i) { - cmGeneratorTarget const* dt = *i; + for (cmTargetDepend const& i : depends) { + cmGeneratorTarget const* dt = i; if (dt->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; } @@ -3639,9 +3694,9 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences() path = lg->GetCurrentBinaryDirectory(); path += "/"; path += dt->GetName(); - path += computeProjectFileExtension(dt); + path += computeProjectFileExtension(dt, *this->Configurations.begin()); } - this->ConvertToWindowsSlash(path); + ConvertToWindowsSlash(path); (*this->BuildFileStream) << cmVS10EscapeXML(path) << "\">\n"; this->WriteString("<Project>", 3); (*this->BuildFileStream) << "{" << this->GlobalGenerator->GetGUID(name) @@ -3713,10 +3768,9 @@ void cmVisualStudio10TargetGenerator::WriteSDKReferences() cmSystemTools::ExpandListArgument(vsSDKReferences, sdkReferences); this->WriteString("<ItemGroup>\n", 1); hasWrittenItemGroup = true; - for (std::vector<std::string>::iterator ri = sdkReferences.begin(); - ri != sdkReferences.end(); ++ri) { + for (std::string const& ri : sdkReferences) { this->WriteString("<SDKReference Include=\"", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(*ri) << "\"/>\n"; + (*this->BuildFileStream) << cmVS10EscapeXML(ri) << "\"/>\n"; } } @@ -3771,11 +3825,9 @@ void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile() std::string pfxFile; std::vector<cmSourceFile const*> certificates; this->GeneratorTarget->GetCertificates(certificates, ""); - for (std::vector<cmSourceFile const*>::const_iterator si = - certificates.begin(); - si != certificates.end(); ++si) { - pfxFile = this->ConvertPath((*si)->GetFullPath(), false); - this->ConvertToWindowsSlash(pfxFile); + for (cmSourceFile const* si : certificates) { + pfxFile = this->ConvertPath(si->GetFullPath(), false); + ConvertToWindowsSlash(pfxFile); break; } @@ -3785,7 +3837,7 @@ void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile() // Move the manifest to a project directory to avoid clashes std::string artifactDir = this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget); - this->ConvertToWindowsSlash(artifactDir); + ConvertToWindowsSlash(artifactDir); this->WriteString("<PropertyGroup>\n", 1); this->WriteString("<AppxPackageArtifactsDir>", 2); (*this->BuildFileStream) << cmVS10EscapeXML(artifactDir) @@ -3793,7 +3845,7 @@ void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile() this->WriteString("<ProjectPriFullPath>", 2); std::string resourcePriFile = this->DefaultArtifactDir + "/resources.pri"; - this->ConvertToWindowsSlash(resourcePriFile); + ConvertToWindowsSlash(resourcePriFile); (*this->BuildFileStream) << resourcePriFile << "</ProjectPriFullPath>\n"; // If we are missing files and we don't have a certificate and @@ -3804,7 +3856,7 @@ void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile() pfxFile = this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx"; cmSystemTools::CopyAFile(templateFolder + "/Windows_TemporaryKey.pfx", pfxFile, false); - this->ConvertToWindowsSlash(pfxFile); + ConvertToWindowsSlash(pfxFile); this->AddedFiles.push_back(pfxFile); } @@ -3986,12 +4038,10 @@ void cmVisualStudio10TargetGenerator::VerifyNecessaryFiles() std::vector<cmSourceFile const*> extraSources; this->GeneratorTarget->GetExtraSources(extraSources, ""); bool foundManifest = false; - for (std::vector<cmSourceFile const*>::const_iterator si = - extraSources.begin(); - si != extraSources.end(); ++si) { + for (cmSourceFile const* si : extraSources) { // Need to do a lowercase comparison on the filename if ("wmappmanifest.xml" == - cmSystemTools::LowerCase((*si)->GetLocation().GetName())) { + cmSystemTools::LowerCase(si->GetLocation().GetName())) { foundManifest = true; break; } @@ -4050,7 +4100,7 @@ void cmVisualStudio10TargetGenerator::WriteMissingFilesWP80() std::string("/WMAppManifest.xml"); std::string artifactDir = this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget); - this->ConvertToWindowsSlash(artifactDir); + ConvertToWindowsSlash(artifactDir); std::string artifactDirXML = cmVS10EscapeXML(artifactDir); std::string targetNameXML = cmVS10EscapeXML(this->GeneratorTarget->GetName()); @@ -4097,7 +4147,7 @@ void cmVisualStudio10TargetGenerator::WriteMissingFilesWP80() /* clang-format on */ std::string sourceFile = this->ConvertPath(manifestFile, false); - this->ConvertToWindowsSlash(sourceFile); + ConvertToWindowsSlash(sourceFile); this->WriteString("<Xml Include=\"", 2); (*this->BuildFileStream) << cmVS10EscapeXML(sourceFile) << "\">\n"; this->WriteString("<SubType>Designer</SubType>\n", 3); @@ -4107,14 +4157,14 @@ void cmVisualStudio10TargetGenerator::WriteMissingFilesWP80() std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png"; cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png", smallLogo, false); - this->ConvertToWindowsSlash(smallLogo); + ConvertToWindowsSlash(smallLogo); this->WriteString("<Image Include=\"", 2); (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo) << "\" />\n"; this->AddedFiles.push_back(smallLogo); std::string logo = this->DefaultArtifactDir + "/Logo.png"; cmSystemTools::CopyAFile(templateFolder + "/Logo.png", logo, false); - this->ConvertToWindowsSlash(logo); + ConvertToWindowsSlash(logo); this->WriteString("<Image Include=\"", 2); (*this->BuildFileStream) << cmVS10EscapeXML(logo) << "\" />\n"; this->AddedFiles.push_back(logo); @@ -4123,7 +4173,7 @@ void cmVisualStudio10TargetGenerator::WriteMissingFilesWP80() this->DefaultArtifactDir + "/ApplicationIcon.png"; cmSystemTools::CopyAFile(templateFolder + "/ApplicationIcon.png", applicationIcon, false); - this->ConvertToWindowsSlash(applicationIcon); + ConvertToWindowsSlash(applicationIcon); this->WriteString("<Image Include=\"", 2); (*this->BuildFileStream) << cmVS10EscapeXML(applicationIcon) << "\" />\n"; this->AddedFiles.push_back(applicationIcon); @@ -4135,7 +4185,7 @@ void cmVisualStudio10TargetGenerator::WriteMissingFilesWP81() this->DefaultArtifactDir + "/package.appxManifest"; std::string artifactDir = this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget); - this->ConvertToWindowsSlash(artifactDir); + ConvertToWindowsSlash(artifactDir); std::string artifactDirXML = cmVS10EscapeXML(artifactDir); std::string targetNameXML = cmVS10EscapeXML(this->GeneratorTarget->GetName()); @@ -4198,7 +4248,7 @@ void cmVisualStudio10TargetGenerator::WriteMissingFilesWS80() this->DefaultArtifactDir + "/package.appxManifest"; std::string artifactDir = this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget); - this->ConvertToWindowsSlash(artifactDir); + ConvertToWindowsSlash(artifactDir); std::string artifactDirXML = cmVS10EscapeXML(artifactDir); std::string targetNameXML = cmVS10EscapeXML(this->GeneratorTarget->GetName()); @@ -4253,7 +4303,7 @@ void cmVisualStudio10TargetGenerator::WriteMissingFilesWS81() this->DefaultArtifactDir + "/package.appxManifest"; std::string artifactDir = this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget); - this->ConvertToWindowsSlash(artifactDir); + ConvertToWindowsSlash(artifactDir); std::string artifactDirXML = cmVS10EscapeXML(artifactDir); std::string targetNameXML = cmVS10EscapeXML(this->GeneratorTarget->GetName()); @@ -4313,7 +4363,7 @@ void cmVisualStudio10TargetGenerator::WriteMissingFilesWS10_0() this->DefaultArtifactDir + "/package.appxManifest"; std::string artifactDir = this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget); - this->ConvertToWindowsSlash(artifactDir); + ConvertToWindowsSlash(artifactDir); std::string artifactDirXML = cmVS10EscapeXML(artifactDir); std::string targetNameXML = cmVS10EscapeXML(this->GeneratorTarget->GetName()); @@ -4375,7 +4425,7 @@ void cmVisualStudio10TargetGenerator::WriteCommonMissingFiles( cmSystemTools::GetCMakeRoot() + "/Templates/Windows"; std::string sourceFile = this->ConvertPath(manifestFile, false); - this->ConvertToWindowsSlash(sourceFile); + ConvertToWindowsSlash(sourceFile); this->WriteString("<AppxManifest Include=\"", 2); (*this->BuildFileStream) << cmVS10EscapeXML(sourceFile) << "\">\n"; this->WriteString("<SubType>Designer</SubType>\n", 3); @@ -4385,7 +4435,7 @@ void cmVisualStudio10TargetGenerator::WriteCommonMissingFiles( std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png"; cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png", smallLogo, false); - this->ConvertToWindowsSlash(smallLogo); + ConvertToWindowsSlash(smallLogo); this->WriteString("<Image Include=\"", 2); (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo) << "\" />\n"; this->AddedFiles.push_back(smallLogo); @@ -4393,14 +4443,14 @@ void cmVisualStudio10TargetGenerator::WriteCommonMissingFiles( std::string smallLogo44 = this->DefaultArtifactDir + "/SmallLogo44x44.png"; cmSystemTools::CopyAFile(templateFolder + "/SmallLogo44x44.png", smallLogo44, false); - this->ConvertToWindowsSlash(smallLogo44); + ConvertToWindowsSlash(smallLogo44); this->WriteString("<Image Include=\"", 2); (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo44) << "\" />\n"; this->AddedFiles.push_back(smallLogo44); std::string logo = this->DefaultArtifactDir + "/Logo.png"; cmSystemTools::CopyAFile(templateFolder + "/Logo.png", logo, false); - this->ConvertToWindowsSlash(logo); + ConvertToWindowsSlash(logo); this->WriteString("<Image Include=\"", 2); (*this->BuildFileStream) << cmVS10EscapeXML(logo) << "\" />\n"; this->AddedFiles.push_back(logo); @@ -4408,7 +4458,7 @@ void cmVisualStudio10TargetGenerator::WriteCommonMissingFiles( std::string storeLogo = this->DefaultArtifactDir + "/StoreLogo.png"; cmSystemTools::CopyAFile(templateFolder + "/StoreLogo.png", storeLogo, false); - this->ConvertToWindowsSlash(storeLogo); + ConvertToWindowsSlash(storeLogo); this->WriteString("<Image Include=\"", 2); (*this->BuildFileStream) << cmVS10EscapeXML(storeLogo) << "\" />\n"; this->AddedFiles.push_back(storeLogo); @@ -4416,14 +4466,14 @@ void cmVisualStudio10TargetGenerator::WriteCommonMissingFiles( std::string splashScreen = this->DefaultArtifactDir + "/SplashScreen.png"; cmSystemTools::CopyAFile(templateFolder + "/SplashScreen.png", splashScreen, false); - this->ConvertToWindowsSlash(splashScreen); + ConvertToWindowsSlash(splashScreen); this->WriteString("<Image Include=\"", 2); (*this->BuildFileStream) << cmVS10EscapeXML(splashScreen) << "\" />\n"; this->AddedFiles.push_back(splashScreen); // This file has already been added to the build so don't copy it std::string keyFile = this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx"; - this->ConvertToWindowsSlash(keyFile); + ConvertToWindowsSlash(keyFile); this->WriteString("<None Include=\"", 2); (*this->BuildFileStream) << cmVS10EscapeXML(keyFile) << "\" />\n"; } @@ -4453,13 +4503,12 @@ void cmVisualStudio10TargetGenerator::GetCSharpSourceProperties( { if (this->ProjectType == csproj) { const cmPropertyMap& props = sf->GetProperties(); - for (cmPropertyMap::const_iterator p = props.begin(); p != props.end(); - ++p) { + for (auto const& p : props) { static const std::string propNamePrefix = "VS_CSHARP_"; - if (p->first.find(propNamePrefix) == 0) { - std::string tagName = p->first.substr(propNamePrefix.length()); + if (p.first.find(propNamePrefix) == 0) { + std::string tagName = p.first.substr(propNamePrefix.length()); if (!tagName.empty()) { - const std::string val = props.GetPropertyValue(p->first); + const std::string val = props.GetPropertyValue(p.first); if (!val.empty()) { tags[tagName] = val; } else { @@ -4475,11 +4524,10 @@ void cmVisualStudio10TargetGenerator::WriteCSharpSourceProperties( const std::map<std::string, std::string>& tags) { if (!tags.empty()) { - for (std::map<std::string, std::string>::const_iterator i = tags.begin(); - i != tags.end(); ++i) { + for (const auto& i : tags) { this->WriteString("<", 3); - (*this->BuildFileStream) << i->first << ">" << cmVS10EscapeXML(i->second) - << "</" << i->first << ">\n"; + (*this->BuildFileStream) << i.first << ">" << cmVS10EscapeXML(i.second) + << "</" << i.first << ">\n"; } } } @@ -4496,7 +4544,7 @@ void cmVisualStudio10TargetGenerator::GetCSharpSourceLink( if (const char* l = sf->GetProperty("VS_CSHARP_Link")) { link = l; } - this->ConvertToWindowsSlash(link); + ConvertToWindowsSlash(link); } } } @@ -4507,7 +4555,7 @@ std::string cmVisualStudio10TargetGenerator::GetCMakeFilePath( // Always search in the standard modules location. std::string path = cmSystemTools::GetCMakeRoot() + "/"; path += relativeFilePath; - this->ConvertToWindowsSlash(path); + ConvertToWindowsSlash(path); return path; } |