From 59d8cfb85ec964c98ca2c1d6b262d5b26f484c88 Mon Sep 17 00:00:00 2001 From: Vitaly Stakhovsky Date: Mon, 5 Mar 2018 19:21:57 -0500 Subject: [PATCH] cmVisualStudio10TargetGenerator: Use helpers for XML tags Make the XML generating code smaller, more structured, and less error-prone. This is a step towards future XML refactoring. --- Source/cmVisualStudio10TargetGenerator.cxx | 474 +++++++-------------- Source/cmVisualStudio10TargetGenerator.h | 4 + 2 files changed, 166 insertions(+), 312 deletions(-) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index ed4a201517..0fd8043e4e 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -18,6 +18,22 @@ #include #include // IWYU pragma: keep +inline void cmVisualStudio10TargetGenerator::WriteElem(const char* tag, + const char* val, + int indentLevel) +{ + this->WriteString("<", indentLevel); + (*this->BuildFileStream) << tag << ">" << val << "\n"; +} + +inline void cmVisualStudio10TargetGenerator::WriteElem(const char* tag, + std::string const& val, + int indentLevel) +{ + this->WriteString("<", indentLevel); + (*this->BuildFileStream) << tag << ">" << val << "\n"; +} + static void ConvertToWindowsSlash(std::string& s); static std::string cmVS10EscapeXML(std::string arg) @@ -28,6 +44,12 @@ static std::string cmVS10EscapeXML(std::string arg) return arg; } +inline void cmVisualStudio10TargetGenerator::WriteElemEscapeXML( + const char* tag, std::string const& val, int indentLevel) +{ + this->WriteElem(tag, cmVS10EscapeXML(val), indentLevel); +} + static std::string cmVS10EscapeQuotes(std::string arg) { cmSystemTools::ReplaceString(arg, "\"", """); @@ -265,16 +287,10 @@ void cmVisualStudio10TargetGenerator::Generate() } (*this->BuildFileStream) << "\n"; // Tell newer versions to upgrade silently when loading. - this->WriteString("" - "true" - "\n", - 2); + this->WriteElem("NsightTegraUpgradeOnceWithoutPrompt", "true", 2); } else { // Require Nsight Tegra 1.6 for JCompile support. - this->WriteString("" - "7" - "\n", - 2); + this->WriteElem("NsightTegraProjectRevisionNumber", "7", 2); } this->WriteString("\n", 1); } @@ -282,9 +298,7 @@ void cmVisualStudio10TargetGenerator::Generate() if (const char* hostArch = this->GlobalGenerator->GetPlatformToolsetHostArchitecture()) { this->WriteString("\n", 1); - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(hostArch) - << "\n"; + this->WriteElemEscapeXML("PreferredToolArchitecture", hostArch, 2); this->WriteString("\n", 1); } @@ -292,8 +306,7 @@ void cmVisualStudio10TargetGenerator::Generate() this->WriteProjectConfigurations(); } this->WriteString("\n", 1); - this->WriteString("", 2); - (*this->BuildFileStream) << "{" << this->GUID << "}\n"; + this->WriteElem("ProjectGuid", "{" + this->GUID + "}", 2); if (this->MSTools && this->GeneratorTarget->GetType() <= cmStateEnums::GLOBAL_TARGET) { @@ -322,61 +335,45 @@ void cmVisualStudio10TargetGenerator::Generate() this->GeneratorTarget->GetProperty("VS_SCC_PROVIDER"); if (vsProjectName && vsLocalPath && vsProvider) { - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(vsProjectName) - << "\n"; - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(vsLocalPath) - << "\n"; - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(vsProvider) - << "\n"; + this->WriteElemEscapeXML("SccProjectName", vsProjectName, 2); + this->WriteElemEscapeXML("SccLocalPath", vsLocalPath, 2); + this->WriteElemEscapeXML("SccProvider", vsProvider, 2); const char* vsAuxPath = this->GeneratorTarget->GetProperty("VS_SCC_AUXPATH"); if (vsAuxPath) { - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(vsAuxPath) - << "\n"; + this->WriteElemEscapeXML("SccAuxPath", vsAuxPath, 2); } } if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT")) { - this->WriteString("true\n", 2); + this->WriteElem("WinMDAssembly", "true", 2); } const char* vsGlobalKeyword = this->GeneratorTarget->GetProperty("VS_GLOBAL_KEYWORD"); if (!vsGlobalKeyword) { - this->WriteString("Win32Proj\n", 2); + this->WriteElem("Keyword", "Win32Proj", 2); } else { - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(vsGlobalKeyword) - << "\n"; + this->WriteElemEscapeXML("Keyword", vsGlobalKeyword, 2); } const char* vsGlobalRootNamespace = this->GeneratorTarget->GetProperty("VS_GLOBAL_ROOTNAMESPACE"); if (vsGlobalRootNamespace) { - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(vsGlobalRootNamespace) - << "\n"; + this->WriteElemEscapeXML("RootNamespace", vsGlobalRootNamespace, 2); } - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(this->Platform) - << "\n"; + this->WriteElemEscapeXML("Platform", this->Platform, 2); const char* projLabel = this->GeneratorTarget->GetProperty("PROJECT_LABEL"); if (!projLabel) { projLabel = this->Name.c_str(); } - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(projLabel) << "\n"; + this->WriteElemEscapeXML("ProjectName", projLabel, 2); if (const char* targetFrameworkVersion = this->GeneratorTarget->GetProperty( "VS_DOTNET_TARGET_FRAMEWORK_VERSION")) { - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(targetFrameworkVersion) - << "\n"; + this->WriteElemEscapeXML("TargetFrameworkVersion", targetFrameworkVersion, + 2); } // Disable the project upgrade prompt that is displayed the first time a @@ -384,9 +381,7 @@ void cmVisualStudio10TargetGenerator::Generate() // the IDE (respected by VS 2013 and above). if (this->GlobalGenerator->GetVersion() >= cmGlobalVisualStudioGenerator::VS12) { - this->WriteString("NoUpgrade" - "\n", - 2); + this->WriteElem("VCProjectUpgraderObjectName", "NoUpgrade", 2); } std::vector keys = this->GeneratorTarget->GetPropertyKeys(); @@ -437,8 +432,7 @@ void cmVisualStudio10TargetGenerator::Generate() } outputType += "\n"; this->WriteString(outputType.c_str(), 2); - this->WriteString("Properties\n", - 2); + this->WriteElem("AppDesignerFolder", "Properties", 2); } this->WriteString("\n", 1); @@ -635,12 +629,8 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReference( { this->WriteString("BuildFileStream) << cmVS10EscapeXML(ref) << "\">\n"; - this->WriteString("true" - "\n", - 3); - this->WriteString("true" - "\n", - 3); + this->WriteElem("CopyLocalSatelliteAssemblies", "true", 3); + this->WriteElem("ReferenceOutputAssembly", "true", 3); if (!hint.empty()) { const char* privateReference = "True"; if (const char* value = this->GeneratorTarget->GetProperty( @@ -649,10 +639,8 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReference( privateReference = "False"; } } - this->WriteString("", 3); - (*this->BuildFileStream) << privateReference << "\n"; - this->WriteString("", 3); - (*this->BuildFileStream) << hint << "\n"; + this->WriteElem("Private", privateReference, 3); + this->WriteElem("HintPath", hint, 3); } this->WriteDotNetReferenceCustomTags(ref); this->WriteString("\n", 2); @@ -711,9 +699,8 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup() (*this->BuildFileStream) << obj << "\">\n"; if (this->ProjectType != csproj) { - this->WriteString("", 3); std::string hFileName = obj.substr(0, obj.find_last_of(".")) + ".h"; - (*this->BuildFileStream) << hFileName << "\n"; + this->WriteElem("DependentUpon", hFileName, 3); for (std::string const& i : this->Configurations) { this->WritePlatformConfigTag("LogicalName", i, 3); @@ -741,8 +728,7 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup() link = cmsys::SystemTools::GetFilenameName(obj); } if (!link.empty()) { - this->WriteString("", 3); - (*this->BuildFileStream) << link << "\n"; + this->WriteElem("Link", link, 3); } } // Determine if this is a generated resource from a .Designer.cs file @@ -756,9 +742,7 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup() generator = g; } if (!generator.empty()) { - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(generator) - << "\n"; + this->WriteElemEscapeXML("Generator", generator, 3); if (designerResource.find(srcDir) == 0) { designerResource = designerResource.substr(srcDir.length() + 1); } else if (designerResource.find(binDir) == 0) { @@ -768,9 +752,7 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup() cmsys::SystemTools::GetFilenameName(designerResource); } ConvertToWindowsSlash(designerResource); - this->WriteString("", 3); - (*this->BuildFileStream) << designerResource - << "\n"; + this->WriteElem("LastGenOutput", designerResource, 3); } } const cmPropertyMap& props = oi->GetProperties(); @@ -828,11 +810,10 @@ void cmVisualStudio10TargetGenerator::WriteXamlFilesGroup() } if (!link.empty()) { ConvertToWindowsSlash(link); - this->WriteString("", 3); - (*this->BuildFileStream) << link << "\n"; + this->WriteElem("Link", link, 3); } } - this->WriteString("Designer\n", 3); + this->WriteElem("SubType", "Designer", 3); this->WriteString("BuildFileStream) << xamlType << ">\n"; } @@ -894,7 +875,7 @@ void cmVisualStudio10TargetGenerator::WriteWinRTReferences() for (std::string const& ri : references) { this->WriteString("BuildFileStream) << cmVS10EscapeXML(ri) << "\">\n"; - this->WriteString("true\n", 3); + this->WriteElem("IsWinMDFile", "true", 3); this->WriteString("\n", 2); } this->WriteString("\n", 1); @@ -909,11 +890,8 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurations() for (std::string const& c : this->Configurations) { this->WriteString("BuildFileStream) << c << "|" << this->Platform << "\">\n"; - this->WriteString("", 3); - (*this->BuildFileStream) << c << "\n"; - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(this->Platform) - << "\n"; + this->WriteElem("Configuration", c, 3); + this->WriteElemEscapeXML("Platform", this->Platform, 3); this->WriteString("\n", 2); } this->WriteString("\n", 1); @@ -997,9 +975,7 @@ void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValues( useOfMfcValue = "Dynamic"; } } - std::string mfcLine = ""; - mfcLine += useOfMfcValue + "\n"; - this->WriteString(mfcLine.c_str(), 2); + this->WriteElem("UseOfMfc", useOfMfcValue, 2); } if ((this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY && @@ -1008,25 +984,20 @@ void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValues( this->GlobalGenerator->TargetsWindowsPhone() || this->GlobalGenerator->TargetsWindowsStore() || this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_EXTENSIONS")) { - this->WriteString("Unicode\n", 2); + this->WriteElem("CharacterSet", "Unicode", 2); } else if (this->GeneratorTarget->GetType() <= cmStateEnums::MODULE_LIBRARY && this->ClOptions[config]->UsingSBCS()) { - this->WriteString("NotSet\n", 2); + this->WriteElem("CharacterSet", "NotSet", 2); } else { - this->WriteString("MultiByte\n", 2); + this->WriteElem("CharacterSet", "MultiByte", 2); } if (const char* toolset = gg->GetPlatformToolset()) { - std::string pts = ""; - pts += toolset; - pts += "\n"; - this->WriteString(pts.c_str(), 2); + this->WriteElem("PlatformToolset", toolset, 2); } if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") || this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_EXTENSIONS")) { - this->WriteString("true" - "\n", - 2); + this->WriteElem("WindowsAppContainer", "true", 2); } } @@ -1038,26 +1009,21 @@ void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValuesManaged( Options& o = *(this->ClOptions[config]); if (o.IsDebug()) { - this->WriteString("true\n", 2); - this->WriteString("true\n", 2); + this->WriteElem("DebugSymbols", "true", 2); + this->WriteElem("DefineDebug", "true", 2); } std::string outDir = this->GeneratorTarget->GetDirectory(config) + "/"; ConvertToWindowsSlash(outDir); - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(outDir) << "\n"; + this->WriteElemEscapeXML("OutputPath", outDir, 2); if (o.HasFlag("Platform")) { - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(o.GetFlag("Platform")) - << "\n"; + this->WriteElemEscapeXML("PlatformTarget", o.GetFlag("Platform"), 2); o.RemoveFlag("Platform"); } if (const char* toolset = gg->GetPlatformToolset()) { - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(toolset) - << "\n"; + this->WriteElemEscapeXML("PlatformToolset", toolset, 2); } std::string postfixName = cmSystemTools::UpperCase(config); @@ -1067,12 +1033,10 @@ void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValuesManaged( if (const char* postfix = this->GeneratorTarget->GetProperty(postfixName)) { assemblyName += postfix; } - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(assemblyName) - << "\n"; + this->WriteElemEscapeXML("AssemblyName", assemblyName, 2); if (cmStateEnums::EXECUTABLE == this->GeneratorTarget->GetType()) { - this->WriteString("Program\n", 2); + this->WriteElem("StartAction", "Program", 2); this->WriteString("", 2); (*this->BuildFileStream) << cmVS10EscapeXML(outDir) << cmVS10EscapeXML(assemblyName) @@ -1094,27 +1058,20 @@ void cmVisualStudio10TargetGenerator::WriteNsightTegraConfigurationValues( this->WriteString(ntv.c_str(), 2); if (const char* minApi = this->GeneratorTarget->GetProperty("ANDROID_API_MIN")) { - this->WriteString("", 2); - (*this->BuildFileStream) << "android-" << cmVS10EscapeXML(minApi) - << "\n"; + this->WriteElem("AndroidMinAPI", "android-" + cmVS10EscapeXML(minApi), 2); } if (const char* api = this->GeneratorTarget->GetProperty("ANDROID_API")) { - this->WriteString("", 2); - (*this->BuildFileStream) << "android-" << cmVS10EscapeXML(api) - << "\n"; + this->WriteElem("AndroidTargetAPI", "android-" + cmVS10EscapeXML(api), 2); } if (const char* cpuArch = this->GeneratorTarget->GetProperty("ANDROID_ARCH")) { - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(cpuArch) << "\n"; + this->WriteElemEscapeXML("AndroidArch", cpuArch, 2); } if (const char* stlType = this->GeneratorTarget->GetProperty("ANDROID_STL_TYPE")) { - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(stlType) - << "\n"; + this->WriteElemEscapeXML("AndroidStlType", stlType, 2); } } @@ -1199,8 +1156,7 @@ void cmVisualStudio10TargetGenerator::WriteCustomRule( this->GetCSharpSourceLink(source, link); this->WriteSource("None", source, ">\n"); if (!link.empty()) { - this->WriteString("", 3); - (*this->BuildFileStream) << link << "\n"; + this->WriteElem("Link", link, 3); } this->WriteString("\n", 2); this->WriteString("\n", 1); @@ -1372,23 +1328,23 @@ void cmVisualStudio10TargetGenerator::WriteGroups() if (fileName == "wmappmanifest.xml") { this->WriteString("BuildFileStream) << oi << "\">\n"; - this->WriteString("Resource Files\n", 3); + this->WriteElem("Filter", "Resource Files", 3); this->WriteString("\n", 2); } else if (cmSystemTools::GetFilenameExtension(fileName) == ".appxmanifest") { this->WriteString("BuildFileStream) << oi << "\">\n"; - this->WriteString("Resource Files\n", 3); + this->WriteElem("Filter", "Resource Files", 3); this->WriteString("\n", 2); } else if (cmSystemTools::GetFilenameExtension(fileName) == ".pfx") { this->WriteString("BuildFileStream) << oi << "\">\n"; - this->WriteString("Resource Files\n", 3); + this->WriteElem("Filter", "Resource Files", 3); this->WriteString("\n", 2); } else { this->WriteString("BuildFileStream) << oi << "\">\n"; - this->WriteString("Resource Files\n", 3); + this->WriteElem("Filter", "Resource Files", 3); this->WriteString("\n", 2); } } @@ -1404,7 +1360,7 @@ void cmVisualStudio10TargetGenerator::WriteGroups() this->WriteString("BuildFileStream) << cmVS10EscapeXML(obj) << "\">\n"; - this->WriteString("Resource Files\n", 3); + this->WriteElem("Filter", "Resource Files", 3); this->WriteString("\n", 2); } this->WriteString("\n", 1); @@ -1423,10 +1379,8 @@ void cmVisualStudio10TargetGenerator::WriteGroups() (*this->BuildFileStream) << name << "\">\n"; std::string guidName = "SG_Filter_"; guidName += name; - this->WriteString("", 3); std::string guid = this->GlobalGenerator->GetGUID(guidName); - (*this->BuildFileStream) << "{" << guid << "}" - << "\n"; + this->WriteElem("UniqueIdentifier", "{" + guid + "}", 3); this->WriteString("\n", 2); } } @@ -1434,10 +1388,8 @@ void cmVisualStudio10TargetGenerator::WriteGroups() if (!resxObjs.empty() || !this->AddedFiles.empty()) { this->WriteString("\n", 2); std::string guidName = "SG_Filter_Resource Files"; - this->WriteString("", 3); std::string guid = this->GlobalGenerator->GetGUID(guidName); - (*this->BuildFileStream) << "{" << guid << "}" - << "\n"; + this->WriteElem("UniqueIdentifier", "{" + guid + "}", 3); this->WriteString("rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;", 3); (*this->BuildFileStream) << "gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;"; (*this->BuildFileStream) << "mfcribbon-ms\n"; @@ -1508,8 +1460,7 @@ void cmVisualStudio10TargetGenerator::WriteGroupSources( (*this->BuildFileStream) << name << " Include=\"" << cmVS10EscapeXML(path); if (!filter.empty()) { (*this->BuildFileStream) << "\">\n"; - this->WriteString("", 3); - (*this->BuildFileStream) << filter << "\n"; + this->WriteElem("Filter", filter, 3); this->WriteString("BuildFileStream) << name << ">\n"; } else { @@ -1524,13 +1475,12 @@ void cmVisualStudio10TargetGenerator::WriteHeaderSource(cmSourceFile const* sf) std::string const& fileName = sf->GetFullPath(); if (this->IsResxHeader(fileName)) { this->WriteSource("ClInclude", sf, ">\n"); - this->WriteString("CppForm\n", 3); + this->WriteElem("FileType", "CppForm", 3); this->WriteString("\n", 2); } else if (this->IsXamlHeader(fileName)) { this->WriteSource("ClInclude", sf, ">\n"); - this->WriteString("", 3); std::string xamlFileName = fileName.substr(0, fileName.find_last_of(".")); - (*this->BuildFileStream) << xamlFileName << "\n"; + this->WriteElem("DependentUpon", xamlFileName, 3); this->WriteString("\n", 2); } else { this->WriteSource("ClInclude", sf); @@ -1725,19 +1675,13 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf) } } if (!shaderType.empty()) { - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(shaderType) - << "\n"; + this->WriteElemEscapeXML("ShaderType", shaderType, 3); } if (!shaderEntryPoint.empty()) { - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(shaderEntryPoint) - << "\n"; + this->WriteElemEscapeXML("EntryPointName", shaderEntryPoint, 3); } if (!shaderModel.empty()) { - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(shaderModel) - << "\n"; + this->WriteElemEscapeXML("ShaderModel", shaderModel, 3); } if (!outputHeaderFile.empty()) { for (size_t i = 0; i != this->Configurations.size(); ++i) { @@ -1762,47 +1706,33 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf) } } if (!shaderEnableDebug.empty()) { - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(shaderEnableDebug) - << "\n"; + this->WriteElemEscapeXML("EnableDebuggingInformation", shaderEnableDebug, + 3); } if (!shaderDisableOptimizations.empty()) { - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(shaderDisableOptimizations) - << "\n"; + this->WriteElemEscapeXML("DisableOptimizations", + shaderDisableOptimizations, 3); } if (!shaderAdditionalFlags.empty()) { - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(shaderAdditionalFlags) - << "\n"; + this->WriteElemEscapeXML("AdditionalOptions", shaderAdditionalFlags, 3); } if (!settingsGenerator.empty()) { - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(settingsGenerator) - << "\n"; + this->WriteElemEscapeXML("Generator", settingsGenerator, 3); } if (!settingsLastGenOutput.empty()) { - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(settingsLastGenOutput) - << "\n"; + this->WriteElemEscapeXML("LastGenOutput", settingsLastGenOutput, 3); } if (!sourceLink.empty()) { - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(sourceLink) << "\n"; + this->WriteElemEscapeXML("Link", sourceLink, 3); } if (!subType.empty()) { - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(subType) << "\n"; + this->WriteElemEscapeXML("SubType", subType, 3); } if (!copyToOutDir.empty()) { - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(copyToOutDir) - << "\n"; + this->WriteElemEscapeXML("CopyToOutputDirectory", copyToOutDir, 3); } if (!includeInVsix.empty()) { - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(includeInVsix) - << "\n"; + this->WriteElemEscapeXML("IncludeInVSIX", includeInVsix, 3); } // write source file specific tags this->WriteCSharpSourceProperties(sourceFileTags); @@ -2057,13 +1987,9 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( firstString = ""; hasFlags = true; if (lang == "CUDA") { - this->WriteString("", 3); - (*this->BuildFileStream) << "$(IntDir)/" << objectName - << "\n"; + this->WriteElem("CompileOut", "$(IntDir)/" + objectName, 3); } else { - this->WriteString("", 3); - (*this->BuildFileStream) << "$(IntDir)/" << objectName - << "\n"; + this->WriteElem("ObjectFileName", "$(IntDir)/" + objectName, 3); } } for (std::string const& config : this->Configurations) { @@ -2163,10 +2089,9 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( (*this->BuildFileStream) << firstString; firstString = ""; // only do firstString once hasFlags = true; - this->WriteString("", 3); const std::string& fileName = source->GetFullPath(); std::string xamlFileName = fileName.substr(0, fileName.find_last_of(".")); - (*this->BuildFileStream) << xamlFileName << "\n"; + this->WriteElem("DependentUpon", xamlFileName, 3); } if (this->ProjectType == csproj) { std::string f = source->GetFullPath(); @@ -2214,9 +2139,7 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions() } this->WriteString("\n", 1); - this->WriteString("<_ProjectFileVersion>10.0.20506.1" - "\n", - 2); + this->WriteElem("_ProjectFileVersion", "10.0.20506.1", 2); for (std::string const& config : this->Configurations) { if (ttype >= cmStateEnums::UTILITY) { this->WritePlatformConfigTag("IntDir", config, 2); @@ -2521,9 +2444,7 @@ void cmVisualStudio10TargetGenerator::WriteClOptions( if (this->NsightTegra) { if (const char* processMax = this->GeneratorTarget->GetProperty("ANDROID_PROCESS_MAX")) { - this->WriteString("", 3); - *this->BuildFileStream << cmVS10EscapeXML(processMax) - << "\n"; + this->WriteElemEscapeXML("ProcessMax", processMax, 3); } } @@ -2531,12 +2452,9 @@ void cmVisualStudio10TargetGenerator::WriteClOptions( cmsys::RegularExpression clangToolset("v[0-9]+_clang_.*"); const char* toolset = this->GlobalGenerator->GetPlatformToolset(); if (toolset && clangToolset.find(toolset)) { - this->WriteString("" - "$(IntDir)%(filename).obj" - "\n", - 3); + this->WriteElem("ObjectFileName", "$(IntDir)%(filename).obj", 3); } else { - this->WriteString("$(IntDir)\n", 3); + this->WriteElem("ObjectFileName", "$(IntDir)", 3); } // If not in debug mode, write the DebugInformationFormat field @@ -2552,9 +2470,7 @@ void cmVisualStudio10TargetGenerator::WriteClOptions( std::string pdb = this->GeneratorTarget->GetCompilePDBPath(configName); if (!pdb.empty()) { ConvertToWindowsSlash(pdb); - this->WriteString("", 3); - *this->BuildFileStream << cmVS10EscapeXML(pdb) - << "\n"; + this->WriteElemEscapeXML("ProgramDataBaseFileName", pdb, 3); } } @@ -2973,9 +2889,7 @@ void cmVisualStudio10TargetGenerator::WriteLibOptions( if (this->GlobalGenerator->TargetsWindowsPhone() || this->GlobalGenerator->TargetsWindowsStore()) { this->WriteString("\n", 2); - this->WriteString("false" - "\n", - 3); + this->WriteElem("GenerateWindowsMetadata", "false", 3); this->WriteString("\n", 2); } } @@ -3026,32 +2940,28 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions( { std::string antBuildPath = rootDir; this->WriteString("\n", 2); - this->WriteString("", 3); ConvertToWindowsSlash(antBuildPath); - (*this->BuildFileStream) << cmVS10EscapeXML(antBuildPath) - << "\n"; + this->WriteElemEscapeXML("AntBuildPath", antBuildPath, 3); } if (this->GeneratorTarget->GetPropertyAsBool("ANDROID_SKIP_ANT_STEP")) { - this->WriteString("true\n", 3); + this->WriteElem("SkipAntStep", "true", 3); } if (this->GeneratorTarget->GetPropertyAsBool("ANDROID_PROGUARD")) { - this->WriteString("true\n", 3); + this->WriteElem("EnableProGuard", "true", 3); } if (const char* proGuardConfigLocation = this->GeneratorTarget->GetProperty("ANDROID_PROGUARD_CONFIG_PATH")) { - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(proGuardConfigLocation) - << "\n"; + this->WriteElemEscapeXML("ProGuardConfigLocation", proGuardConfigLocation, + 3); } if (const char* securePropertiesLocation = this->GeneratorTarget->GetProperty("ANDROID_SECURE_PROPS_PATH")) { - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(securePropertiesLocation) - << "\n"; + this->WriteElemEscapeXML("SecurePropertiesLocation", + securePropertiesLocation, 3); } if (const char* nativeLibDirectoriesExpression = @@ -3061,9 +2971,7 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions( ge.Parse(nativeLibDirectoriesExpression); std::string nativeLibDirs = cge->Evaluate(this->LocalGenerator, configName); - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(nativeLibDirs) - << "\n"; + this->WriteElemEscapeXML("NativeLibDirectories", nativeLibDirs, 3); } if (const char* nativeLibDependenciesExpression = @@ -3074,16 +2982,12 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions( ge.Parse(nativeLibDependenciesExpression); std::string nativeLibDeps = cge->Evaluate(this->LocalGenerator, configName); - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(nativeLibDeps) - << "\n"; + this->WriteElemEscapeXML("NativeLibDependencies", nativeLibDeps, 3); } if (const char* javaSourceDir = this->GeneratorTarget->GetProperty("ANDROID_JAVA_SOURCE_DIR")) { - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(javaSourceDir) - << "\n"; + this->WriteElemEscapeXML("JavaSourceDir", javaSourceDir, 3); } if (const char* jarDirectoriesExpression = @@ -3093,31 +2997,23 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions( ge.Parse(jarDirectoriesExpression); std::string jarDirectories = cge->Evaluate(this->LocalGenerator, configName); - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(jarDirectories) - << "\n"; + this->WriteElemEscapeXML("JarDirectories", jarDirectories, 3); } if (const char* jarDeps = this->GeneratorTarget->GetProperty("ANDROID_JAR_DEPENDENCIES")) { - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(jarDeps) - << "\n"; + this->WriteElemEscapeXML("JarDependencies", jarDeps, 3); } if (const char* assetsDirectories = this->GeneratorTarget->GetProperty("ANDROID_ASSETS_DIRECTORIES")) { - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(assetsDirectories) - << "\n"; + this->WriteElemEscapeXML("AssetsDirectories", assetsDirectories, 3); } { std::string manifest_xml = rootDir + "/AndroidManifest.xml"; ConvertToWindowsSlash(manifest_xml); - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(manifest_xml) - << "\n"; + this->WriteElemEscapeXML("AndroidManifestLocation", manifest_xml, 3); } if (const char* antAdditionalOptions = @@ -3335,7 +3231,7 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( cmGeneratorTarget::ModuleDefinitionInfo const* mdi = this->GeneratorTarget->GetModuleDefinitionInfo(config); if (mdi && !mdi->DefFile.empty()) { - linkOptions.AddFlag("ModuleDefinitionFile", mdi->DefFile.c_str()); + linkOptions.AddFlag("ModuleDefinitionFile", mdi->DefFile); } linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries", "%(IgnoreSpecificDefaultLibraries)"); @@ -3418,8 +3314,7 @@ void cmVisualStudio10TargetGenerator::WriteLinkOptions( if (!this->GlobalGenerator->NeedLinkLibraryDependencies( this->GeneratorTarget)) { this->WriteString("\n", 2); - this->WriteString( - "false\n", 3); + this->WriteElem("LinkLibraryDependencies", "false", 3); this->WriteString("\n", 2); } } @@ -3513,15 +3408,11 @@ void cmVisualStudio10TargetGenerator::WriteMidlOptions( this->WriteString("%(AdditionalIncludeDirectories)" "\n", 0); - this->WriteString("$(ProjectDir)/$(IntDir)" - "\n", - 3); - this->WriteString("%(Filename).h\n", 3); - this->WriteString("%(Filename).tlb\n", 3); - this->WriteString("" - "%(Filename)_i.c\n", - 3); - this->WriteString("%(Filename)_p.c\n", 3); + this->WriteElem("OutputDirectory", "$(ProjectDir)/$(IntDir)", 3); + this->WriteElem("HeaderFileName", "%(Filename).h", 3); + this->WriteElem("TypeLibraryName", "%(Filename).tlb", 3); + this->WriteElem("InterfaceIdentifierFileName", "%(Filename)_i.c", 3); + this->WriteElem("ProxyFileName", "%(Filename)_p.c", 3); this->WriteString("\n", 2); } @@ -3613,8 +3504,7 @@ void cmVisualStudio10TargetGenerator::WriteEvent( } comment = cmVS10EscapeComment(comment); if (this->ProjectType != csproj) { - this->WriteString("", 3); - (*this->BuildFileStream) << cmVS10EscapeXML(comment) << "\n"; + this->WriteElemEscapeXML("Message", comment, 3); this->WriteString("", 3); } else { std::string strippedComment = comment; @@ -3667,17 +3557,13 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences() } ConvertToWindowsSlash(path); (*this->BuildFileStream) << cmVS10EscapeXML(path) << "\">\n"; - this->WriteString("", 3); - (*this->BuildFileStream) << "{" << this->GlobalGenerator->GetGUID(name) - << "}"; - (*this->BuildFileStream) << "\n"; - this->WriteString("", 3); - (*this->BuildFileStream) << name << "\n"; + this->WriteElem("Project", + "{" + this->GlobalGenerator->GetGUID(name) + "}", 3); + this->WriteElem("Name", name, 3); this->WriteDotNetReferenceCustomTags(name); if (csproj == this->ProjectType) { if (!this->GlobalGenerator->TargetCanBeReferenced(dt)) { - this->WriteString( - "false\n", 3); + this->WriteElem("ReferenceOutputAssembly", "false", 3); } } this->WriteString("\n", 2); @@ -3807,14 +3693,12 @@ void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile() this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget); ConvertToWindowsSlash(artifactDir); this->WriteString("\n", 1); - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(artifactDir) - << "\\\n"; - this->WriteString("", 2); + this->WriteElemEscapeXML("AppxPackageArtifactsDir", artifactDir + "\\", + 2); std::string resourcePriFile = this->DefaultArtifactDir + "/resources.pri"; ConvertToWindowsSlash(resourcePriFile); - (*this->BuildFileStream) << resourcePriFile << "\n"; + this->WriteElem("ProjectPriFullPath", resourcePriFile, 2); // If we are missing files and we don't have a certificate and // aren't targeting WP8.0, add a default certificate @@ -3828,26 +3712,18 @@ void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile() this->AddedFiles.push_back(pfxFile); } - this->WriteString("<", 2); - (*this->BuildFileStream) << "PackageCertificateKeyFile>" << pfxFile - << "\n"; + this->WriteElem("PackageCertificateKeyFile", pfxFile, 2); std::string thumb = cmSystemTools::ComputeCertificateThumbprint(pfxFile); if (!thumb.empty()) { - this->WriteString("", 2); - (*this->BuildFileStream) << thumb - << "\n"; + this->WriteElem("PackageCertificateThumbprint", thumb, 2); } this->WriteString("\n", 1); } else if (!pfxFile.empty()) { this->WriteString("\n", 1); - this->WriteString("<", 2); - (*this->BuildFileStream) << "PackageCertificateKeyFile>" << pfxFile - << "\n"; + this->WriteElem("PackageCertificateKeyFile", pfxFile, 2); std::string thumb = cmSystemTools::ComputeCertificateThumbprint(pfxFile); if (!thumb.empty()) { - this->WriteString("", 2); - (*this->BuildFileStream) << thumb - << "\n"; + this->WriteElem("PackageCertificateThumbprint", thumb, 2); } this->WriteString("\n", 1); } @@ -3895,45 +3771,29 @@ void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings() bool const isWindowsStore = this->GlobalGenerator->TargetsWindowsStore(); std::string const& v = this->GlobalGenerator->GetSystemVersion(); if (isWindowsPhone || isWindowsStore) { - this->WriteString("", 2); - (*this->BuildFileStream) - << (isWindowsPhone ? "Windows Phone" : "Windows Store") - << "\n"; - this->WriteString("en-US" - "\n", - 2); + this->WriteElem("ApplicationType", + (isWindowsPhone ? "Windows Phone" : "Windows Store"), 2); + this->WriteElem("DefaultLanguage", "en-US", 2); if (cmHasLiteralPrefix(v, "10.0")) { - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML("10.0") - << "\n"; + this->WriteElemEscapeXML("ApplicationTypeRevision", "10.0", 2); // Visual Studio 14.0 is necessary for building 10.0 apps - this->WriteString("14.0" - "\n", - 2); + this->WriteElem("MinimumVisualStudioVersion", "14.0", 2); if (this->GeneratorTarget->GetType() < cmStateEnums::UTILITY) { isAppContainer = true; } } else if (v == "8.1") { - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(v) - << "\n"; + this->WriteElemEscapeXML("ApplicationTypeRevision", v, 2); // Visual Studio 12.0 is necessary for building 8.1 apps - this->WriteString("12.0" - "\n", - 2); + this->WriteElem("MinimumVisualStudioVersion", "12.0", 2); if (this->GeneratorTarget->GetType() < cmStateEnums::UTILITY) { isAppContainer = true; } } else if (v == "8.0") { - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(v) - << "\n"; + this->WriteElemEscapeXML("ApplicationTypeRevision", v, 2); // Visual Studio 11.0 is necessary for building 8.0 apps - this->WriteString("11.0" - "\n", - 2); + this->WriteElem("MinimumVisualStudioVersion", "11.0", 2); if (isWindowsStore && this->GeneratorTarget->GetType() < cmStateEnums::UTILITY) { @@ -3941,52 +3801,42 @@ void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings() } else if (isWindowsPhone && this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) { - this->WriteString("true\n", 2); - this->WriteString("", 2); - (*this->BuildFileStream) - << cmVS10EscapeXML(this->Name) - << "_$(Configuration)_$(Platform).xap\n"; + this->WriteElem("XapOutputs", "true", 2); + this->WriteElem("XapFilename", cmVS10EscapeXML(this->Name) + + "_$(Configuration)_$(Platform).xap", + 2); } } } if (isAppContainer) { - this->WriteString("true" - "\n", - 2); + this->WriteElem("AppContainerApplication", "true", 2); } else if (this->Platform == "ARM64") { - this->WriteString("true" - "\n", - 2); + this->WriteElem("WindowsSDKDesktopARM64Support", "true", 2); } else if (this->Platform == "ARM") { - this->WriteString("true" - "\n", - 2); + this->WriteElem("WindowsSDKDesktopARMSupport", "true", 2); } std::string const& targetPlatformVersion = gg->GetWindowsTargetPlatformVersion(); if (!targetPlatformVersion.empty()) { - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(targetPlatformVersion) - << "\n"; + this->WriteElemEscapeXML("WindowsTargetPlatformVersion", + targetPlatformVersion, 2); } const char* targetPlatformMinVersion = this->GeneratorTarget->GetProperty( "VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION"); if (targetPlatformMinVersion) { - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(targetPlatformMinVersion) - << "\n"; + this->WriteElemEscapeXML("WindowsTargetPlatformMinVersion", + targetPlatformMinVersion, 2); } else if (isWindowsStore && cmHasLiteralPrefix(v, "10.0")) { // If the min version is not set, then use the TargetPlatformVersion if (!targetPlatformVersion.empty()) { - this->WriteString("", 2); - (*this->BuildFileStream) << cmVS10EscapeXML(targetPlatformVersion) - << "\n"; + this->WriteElemEscapeXML("WindowsTargetPlatformMinVersion", + targetPlatformVersion, 2); } } // Added IoT Startup Task support if (this->GeneratorTarget->GetPropertyAsBool("VS_IOT_STARTUP_TASK")) { - this->WriteString("true\n", 2); + this->WriteElem("ContainsStartupTask", "true", 2); } } @@ -4117,7 +3967,7 @@ void cmVisualStudio10TargetGenerator::WriteMissingFilesWP80() ConvertToWindowsSlash(sourceFile); this->WriteString("BuildFileStream) << cmVS10EscapeXML(sourceFile) << "\">\n"; - this->WriteString("Designer\n", 3); + this->WriteElem("SubType", "Designer", 3); this->WriteString("\n", 2); this->AddedFiles.push_back(sourceFile); @@ -4395,7 +4245,7 @@ void cmVisualStudio10TargetGenerator::WriteCommonMissingFiles( ConvertToWindowsSlash(sourceFile); this->WriteString("BuildFileStream) << cmVS10EscapeXML(sourceFile) << "\">\n"; - this->WriteString("Designer\n", 3); + this->WriteElem("SubType", "Designer", 3); this->WriteString("\n", 2); this->AddedFiles.push_back(sourceFile); diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h index 124db4e6ba..64121eda1d 100644 --- a/Source/cmVisualStudio10TargetGenerator.h +++ b/Source/cmVisualStudio10TargetGenerator.h @@ -55,6 +55,10 @@ private: std::string ConvertPath(std::string const& path, bool forceRelative); void WriteString(const char* line, int indentLevel); + void WriteElem(const char* tag, const char* val, int indentLevel); + void WriteElem(const char* tag, std::string const& val, int indentLevel); + void WriteElemEscapeXML(const char* tag, std::string const& val, + int indentLevel); void WriteProjectConfigurations(); void WriteProjectConfigurationValues(); void WriteMSToolConfigurationValues(std::string const& config);