diff options
author | Brad King <brad.king@kitware.com> | 2018-03-12 17:41:11 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2018-03-12 17:41:28 (GMT) |
commit | 746ebaf563baa76613d6629a8d53cdeffb6d8a85 (patch) | |
tree | de6178487aa96b9675831bd293fd9a755811c283 | |
parent | fac050ec8d10f7ad8488ff214f8a556a307c46af (diff) | |
parent | 90086767ddad60205302ad88257d60d68fc7fd0a (diff) | |
download | CMake-746ebaf563baa76613d6629a8d53cdeffb6d8a85.zip CMake-746ebaf563baa76613d6629a8d53cdeffb6d8a85.tar.gz CMake-746ebaf563baa76613d6629a8d53cdeffb6d8a85.tar.bz2 |
Merge topic 'xml-raii'
90086767dd cmGlobalVisualStudio10Generator: Use cmXMLWriter RAII helpers
8401b6ac4e cmXMLWriter: Add RAII helpers to allow DOM-like syntax
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1818
-rw-r--r-- | Source/cmGlobalVisualStudio10Generator.cxx | 193 | ||||
-rw-r--r-- | Source/cmXMLWriter.h | 52 |
2 files changed, 130 insertions, 115 deletions
diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index 73a5dae..205e0d0 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -636,126 +636,89 @@ bool cmGlobalVisualStudio10Generator::FindVCTargetsPath(cmMakefile* mf) cmsys::ofstream fout(vcxprojAbs.c_str()); cmXMLWriter xw(fout); - /* clang-format off */ - xw.StartDocument(); - xw.StartElement("Project"); - xw.Attribute("DefaultTargets", "Build"); - xw.Attribute("ToolsVersion", "4.0"); - xw.Attribute("xmlns", - "http://schemas.microsoft.com/developer/msbuild/2003"); - if (this->IsNsightTegra()) { - xw.StartElement("PropertyGroup"); - xw.Attribute("Label", "NsightTegraProject"); - xw.StartElement("NsightTegraProjectRevisionNumber"); - xw.Content("6"); - xw.EndElement(); // NsightTegraProjectRevisionNumber - xw.EndElement(); // PropertyGroup - } - xw.StartElement("ItemGroup"); - xw.Attribute("Label", "ProjectConfigurations"); - xw.StartElement("ProjectConfiguration"); - xw.Attribute("Include", "Debug|" + this->GetPlatformName()); - xw.StartElement("Configuration"); - xw.Content("Debug"); - xw.EndElement(); // Configuration - xw.StartElement("Platform"); - xw.Content(this->GetPlatformName()); - xw.EndElement(); // Platform - xw.EndElement(); // ProjectConfiguration - xw.EndElement(); // ItemGroup - xw.StartElement("PropertyGroup"); - xw.Attribute("Label", "Globals"); - xw.StartElement("ProjectGuid"); - xw.Content("{F3FC6D86-508D-3FB1-96D2-995F08B142EC}"); - xw.EndElement(); // ProjectGuid - xw.StartElement("Keyword"); - xw.Content("Win32Proj"); - xw.EndElement(); // Keyword - xw.StartElement("Platform"); - xw.Content(this->GetPlatformName()); - xw.EndElement(); // Platform - if (this->GetSystemName() == "WindowsPhone") { - xw.StartElement("ApplicationType"); - xw.Content("Windows Phone"); - xw.EndElement(); // ApplicationType - xw.StartElement("ApplicationTypeRevision"); - xw.Content(this->GetSystemVersion()); - xw.EndElement(); // ApplicationTypeRevision - } else if (this->GetSystemName() == "WindowsStore") { - xw.StartElement("ApplicationType"); - xw.Content("Windows Store"); - xw.EndElement(); // ApplicationType - xw.StartElement("ApplicationTypeRevision"); - xw.Content(this->GetSystemVersion()); - xw.EndElement(); // ApplicationTypeRevision - } - if (!this->WindowsTargetPlatformVersion.empty()) { - xw.StartElement("WindowsTargetPlatformVersion"); - xw.Content(this->WindowsTargetPlatformVersion); - xw.EndElement(); // WindowsTargetPlatformVersion - } - if (this->GetPlatformName() == "ARM64") { - xw.StartElement("WindowsSDKDesktopARM64Support"); - xw.Content("true"); - xw.EndElement(); // WindowsSDK64DesktopARMSupport - } - else if (this->GetPlatformName() == "ARM") { - xw.StartElement("WindowsSDKDesktopARMSupport"); - xw.Content("true"); - xw.EndElement(); // WindowsSDKDesktopARMSupport - } - xw.EndElement(); // PropertyGroup - xw.StartElement("Import"); - xw.Attribute("Project", - "$(VCTargetsPath)\\Microsoft.Cpp.Default.props"); - xw.EndElement(); // Import + cmXMLDocument doc(xw); + cmXMLElement eprj(doc, "Project"); + eprj.Attribute("DefaultTargets", "Build"); + eprj.Attribute("ToolsVersion", "4.0"); + eprj.Attribute("xmlns", + "http://schemas.microsoft.com/developer/msbuild/2003"); + if (this->IsNsightTegra()) { + cmXMLElement epg(eprj, "PropertyGroup"); + epg.Attribute("Label", "NsightTegraProject"); + cmXMLElement(epg, "NsightTegraProjectRevisionNumber").Content("6"); + } + { + cmXMLElement eig(eprj, "ItemGroup"); + eig.Attribute("Label", "ProjectConfigurations"); + cmXMLElement epc(eig, "ProjectConfiguration"); + epc.Attribute("Include", "Debug|" + this->GetPlatformName()); + cmXMLElement(epc, "Configuration").Content("Debug"); + cmXMLElement(epc, "Platform").Content(this->GetPlatformName()); + } + { + cmXMLElement epg(eprj, "PropertyGroup"); + epg.Attribute("Label", "Globals"); + cmXMLElement(epg, "ProjectGuid") + .Content("{F3FC6D86-508D-3FB1-96D2-995F08B142EC}"); + cmXMLElement(epg, "Keyword").Content("Win32Proj"); + cmXMLElement(epg, "Platform").Content(this->GetPlatformName()); + if (this->GetSystemName() == "WindowsPhone") { + cmXMLElement(epg, "ApplicationType").Content("Windows Phone"); + cmXMLElement(epg, "ApplicationTypeRevision") + .Content(this->GetSystemVersion()); + } else if (this->GetSystemName() == "WindowsStore") { + cmXMLElement(epg, "ApplicationType").Content("Windows Store"); + cmXMLElement(epg, "ApplicationTypeRevision") + .Content(this->GetSystemVersion()); + } + if (!this->WindowsTargetPlatformVersion.empty()) { + cmXMLElement(epg, "WindowsTargetPlatformVersion") + .Content(this->WindowsTargetPlatformVersion); + } + if (this->GetPlatformName() == "ARM64") { + cmXMLElement(epg, "WindowsSDKDesktopARM64Support").Content("true"); + } else if (this->GetPlatformName() == "ARM") { + cmXMLElement(epg, "WindowsSDKDesktopARMSupport").Content("true"); + } + } + cmXMLElement(eprj, "Import") + .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props"); if (!this->GeneratorToolsetHostArchitecture.empty()) { - xw.StartElement("PropertyGroup"); - xw.StartElement("PreferredToolArchitecture"); - xw.Content(this->GeneratorToolsetHostArchitecture); - xw.EndElement(); // PreferredToolArchitecture - xw.EndElement(); // PropertyGroup + cmXMLElement epg(eprj, "PropertyGroup"); + cmXMLElement(epg, "PreferredToolArchitecture") + .Content(this->GeneratorToolsetHostArchitecture); } - xw.StartElement("PropertyGroup"); - xw.Attribute("Label", "Configuration"); - xw.StartElement("ConfigurationType"); + { + cmXMLElement epg(eprj, "PropertyGroup"); + epg.Attribute("Label", "Configuration"); + { + cmXMLElement ect(epg, "ConfigurationType"); + if (this->IsNsightTegra()) { + // Tegra-Android platform does not understand "Utility". + ect.Content("StaticLibrary"); + } else { + ect.Content("Utility"); + } + } + cmXMLElement(epg, "CharacterSet").Content("MultiByte"); if (this->IsNsightTegra()) { - // Tegra-Android platform does not understand "Utility". - xw.Content("StaticLibrary"); + cmXMLElement(epg, "NdkToolchainVersion") + .Content(this->GetPlatformToolsetString()); } else { - xw.Content("Utility"); + cmXMLElement(epg, "PlatformToolset") + .Content(this->GetPlatformToolsetString()); } - xw.EndElement(); // ConfigurationType - xw.StartElement("CharacterSet"); - xw.Content("MultiByte"); - xw.EndElement(); // CharacterSet - if (this->IsNsightTegra()) { - xw.StartElement("NdkToolchainVersion"); - xw.Content(this->GetPlatformToolsetString()); - xw.EndElement(); // NdkToolchainVersion - } else { - xw.StartElement("PlatformToolset"); - xw.Content(this->GetPlatformToolsetString()); - xw.EndElement(); // PlatformToolset - } - xw.EndElement(); // PropertyGroup - xw.StartElement("Import"); - xw.Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props"); - xw.EndElement(); // Import - xw.StartElement("ItemDefinitionGroup"); - xw.StartElement("PostBuildEvent"); - xw.StartElement("Command"); - xw.Content("echo VCTargetsPath=$(VCTargetsPath)"); - xw.EndElement(); // Command - xw.EndElement(); // PostBuildEvent - xw.EndElement(); // ItemDefinitionGroup - xw.StartElement("Import"); - xw.Attribute("Project", - "$(VCTargetsPath)\\Microsoft.Cpp.targets"); - xw.EndElement(); // Import - xw.EndElement(); // Project - xw.EndDocument(); - /* clang-format on */ + } + cmXMLElement(eprj, "Import") + .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props"); + { + cmXMLElement eidg(eprj, "ItemDefinitionGroup"); + cmXMLElement epbe(eidg, "PostBuildEvent"); + cmXMLElement(epbe, "Command") + .Content("echo VCTargetsPath=$(VCTargetsPath)"); + } + cmXMLElement(eprj, "Import") + .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets"); } std::vector<std::string> cmd; diff --git a/Source/cmXMLWriter.h b/Source/cmXMLWriter.h index 7bae21e..80940ee 100644 --- a/Source/cmXMLWriter.h +++ b/Source/cmXMLWriter.h @@ -133,4 +133,56 @@ private: bool IsContent; }; +class cmXMLElement; // IWYU pragma: keep + +class cmXMLDocument +{ +public: + cmXMLDocument(cmXMLWriter& xml) + : xmlwr(xml) + { + xmlwr.StartDocument(); + } + ~cmXMLDocument() { xmlwr.EndDocument(); } +private: + friend class cmXMLElement; + cmXMLWriter& xmlwr; +}; + +class cmXMLElement +{ +public: + cmXMLElement(cmXMLWriter& xml, const char* tag) + : xmlwr(xml) + { + xmlwr.StartElement(tag); + } + cmXMLElement(cmXMLElement& par, const char* tag) + : xmlwr(par.xmlwr) + { + xmlwr.StartElement(tag); + } + cmXMLElement(cmXMLDocument& doc, const char* tag) + : xmlwr(doc.xmlwr) + { + xmlwr.StartElement(tag); + } + ~cmXMLElement() { xmlwr.EndElement(); } + + template <typename T> + cmXMLElement& Attribute(const char* name, T const& value) + { + xmlwr.Attribute(name, value); + return *this; + } + template <typename T> + void Content(T const& content) + { + xmlwr.Content(content); + } + +private: + cmXMLWriter& xmlwr; +}; + #endif |