From 80767dd50e9898002253f383e9029dcc9da9f4c4 Mon Sep 17 00:00:00 2001 From: Vitaly Stakhovsky Date: Tue, 27 Mar 2018 17:39:19 -0400 Subject: VS: Simplify XML code Get rid of suffix arguments --- Source/cmLocalVisualStudio7Generator.cxx | 26 ++++++++--------- Source/cmVisualStudio10TargetGenerator.cxx | 45 ++++++++++++++---------------- Source/cmVisualStudio10TargetGenerator.h | 3 +- Source/cmVisualStudioGeneratorOptions.cxx | 9 ++---- Source/cmVisualStudioGeneratorOptions.h | 2 -- 5 files changed, 35 insertions(+), 50 deletions(-) diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index c7bb38cc..91ee09f 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -792,10 +792,9 @@ void cmLocalVisualStudio7Generator::WriteConfiguration( << "\\$(ConfigurationName)\"\n"; } targetOptions.OutputAdditionalIncludeDirectories( - fout, "\t\t\t\t", "\n", - this->FortranProject ? "Fortran" : langForClCompile); + fout, "\t\t\t\t", this->FortranProject ? "Fortran" : langForClCompile); targetOptions.OutputFlagMap(fout, "\t\t\t\t"); - targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n", + targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", langForClCompile); fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n"; if (target->GetType() <= cmStateEnums::OBJECT_LIBRARY) { @@ -815,11 +814,10 @@ void cmLocalVisualStudio7Generator::WriteConfiguration( "\t\t\t\tName=\"MASM\"\n" ; /* clang-format on */ - targetOptions.OutputAdditionalIncludeDirectories(fout, "\t\t\t\t", "\n", + targetOptions.OutputAdditionalIncludeDirectories(fout, "\t\t\t\t", "ASM_MASM"); // Use same preprocessor definitions as VCCLCompilerTool. - targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n", - "ASM_MASM"); + targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "ASM_MASM"); masmOptions.OutputFlagMap(fout, "\t\t\t\t"); /* clang-format off */ fout << @@ -837,18 +835,16 @@ void cmLocalVisualStudio7Generator::WriteConfiguration( tool = "VFResourceCompilerTool"; } fout << "\t\t\t\n"; + targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "RC"); + fout << "\t\t\t/>\n"; tool = "VCMIDLTool"; if (this->FortranProject) { tool = "VFMIDLTool"; } fout << "\t\t\tGetPlatformName() == "x64") { fout << "\t\t\t\tTargetEnvironment=\"3\"\n"; @@ -1686,9 +1682,9 @@ bool cmLocalVisualStudio7Generator::WriteGroup( fileOptions.AddIncludes(includes); fileOptions.OutputFlagMap(fout, "\t\t\t\t\t"); fileOptions.OutputAdditionalIncludeDirectories( - fout, "\t\t\t\t\t", "\n", + fout, "\t\t\t\t\t", ppLang == "CXX" && this->FortranProject ? "Fortran" : ppLang); - fileOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t\t", "\n", + fileOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t\t", ppLang); } if (!fc.AdditionalDeps.empty()) { @@ -2071,7 +2067,7 @@ void cmVS7GeneratorOptions::OutputFlag(std::ostream& fout, const char* indent, { fout << indent << tag << "=\""; fout << cmLocalVisualStudio7GeneratorEscapeForXML(content); - fout << "\""; + fout << "\"\n"; } // This class is used to parse an existing vs 7 project diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index f1aed88..4bd07ef 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -86,12 +86,12 @@ public: // use the configuration specific tag for PreprocessorDefinitions fout << indent; this->TargetGenerator->WritePlatformConfigTag( - tag, this->GetConfiguration(), 0, 0, 0, &fout); + tag, this->GetConfiguration(), 0); } else { fout << indent << "<" << tag << ">"; } fout << cmVS10EscapeXML(content); - fout << ""; + fout << "\n"; } private: @@ -218,12 +218,10 @@ cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator() void cmVisualStudio10TargetGenerator::WritePlatformConfigTag( const char* tag, const std::string& config, int indentLevel, - const char* attribute, const char* end, std::ostream* stream) + const char* attribute) { - if (!stream) { - stream = this->BuildFileStream; - } + std::ostream* stream = this->BuildFileStream; stream->fill(' '); stream->width(indentLevel * 2); (*stream) << ""; // applies indentation @@ -244,8 +242,8 @@ void cmVisualStudio10TargetGenerator::WritePlatformConfigTag( } // close the tag (*stream) << ">"; - if (end) { - (*stream) << end; + if (attribute) { + (*stream) << "\n"; } } @@ -972,7 +970,7 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues() { for (std::string const& c : this->Configurations) { this->WritePlatformConfigTag("PropertyGroup", c, 1, - " Label=\"Configuration\"", "\n"); + " Label=\"Configuration\""); if (this->ProjectType != csproj) { std::string configType = ""; @@ -1312,8 +1310,7 @@ void cmVisualStudio10TargetGenerator::WriteCustomRuleCSharp( attributes << "\n Name=\"" << name << "\""; attributes << "\n Inputs=\"" << inputs << "\""; attributes << "\n Outputs=\"" << outputs << "\""; - this->WritePlatformConfigTag("Target", config, 1, attributes.str().c_str(), - "\n"); + this->WritePlatformConfigTag("Target", config, 1, attributes.str().c_str()); if (!comment.empty()) { this->WriteString("BuildFileStream) << "echo " << cmVS10EscapeXML(comment) @@ -2127,10 +2124,10 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( clOptions.SetConfiguration(config); clOptions.PrependInheritedString("AdditionalOptions"); clOptions.OutputAdditionalIncludeDirectories(*this->BuildFileStream, - " ", "\n", lang); + " ", lang); clOptions.OutputFlagMap(*this->BuildFileStream, " "); clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ", - "\n", lang); + lang); } } if (this->IsXamlSource(source->GetFullPath())) { @@ -2486,10 +2483,10 @@ void cmVisualStudio10TargetGenerator::WriteClOptions( this->WriteString("\n", 2); clOptions.PrependInheritedString("AdditionalOptions"); clOptions.OutputAdditionalIncludeDirectories( - *this->BuildFileStream, " ", "\n", this->LangForClCompile); + *this->BuildFileStream, " ", this->LangForClCompile); clOptions.OutputFlagMap(*this->BuildFileStream, " "); clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ", - "\n", this->LangForClCompile); + this->LangForClCompile); if (this->NsightTegra) { if (const char* processMax = @@ -2575,9 +2572,9 @@ void cmVisualStudio10TargetGenerator::WriteRCOptions( Options& rcOptions = *(this->RcOptions[configName]); rcOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ", - "\n", "RC"); + "RC"); rcOptions.OutputAdditionalIncludeDirectories(*this->BuildFileStream, - " ", "\n", "RC"); + " ", "RC"); rcOptions.PrependInheritedString("AdditionalOptions"); rcOptions.OutputFlagMap(*this->BuildFileStream, " "); @@ -2711,9 +2708,9 @@ void cmVisualStudio10TargetGenerator::WriteCudaOptions( Options& cudaOptions = *(this->CudaOptions[configName]); cudaOptions.OutputAdditionalIncludeDirectories(*this->BuildFileStream, - " ", "\n", "CUDA"); + " ", "CUDA"); cudaOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ", - "\n", "CUDA"); + "CUDA"); cudaOptions.PrependInheritedString("AdditionalOptions"); cudaOptions.OutputFlagMap(*this->BuildFileStream, " "); @@ -2836,11 +2833,11 @@ void cmVisualStudio10TargetGenerator::WriteMasmOptions( // Preprocessor definitions and includes are shared with clOptions. Options& clOptions = *(this->ClOptions[configName]); clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ", - "\n", "ASM_MASM"); + "ASM_MASM"); Options& masmOptions = *(this->MasmOptions[configName]); masmOptions.OutputAdditionalIncludeDirectories(*this->BuildFileStream, - " ", "\n", "ASM_MASM"); + " ", "ASM_MASM"); masmOptions.PrependInheritedString("AdditionalOptions"); masmOptions.OutputFlagMap(*this->BuildFileStream, " "); @@ -2897,16 +2894,16 @@ void cmVisualStudio10TargetGenerator::WriteNasmOptions( this->GetIncludes(configName, "ASM_NASM"); Options& nasmOptions = *(this->NasmOptions[configName]); nasmOptions.OutputAdditionalIncludeDirectories(*this->BuildFileStream, - " ", "\n", "ASM_NASM"); + " ", "ASM_NASM"); nasmOptions.OutputFlagMap(*this->BuildFileStream, " "); nasmOptions.PrependInheritedString("AdditionalOptions"); nasmOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ", - "\n", "ASM_NASM"); + "ASM_NASM"); // Preprocessor definitions and includes are shared with clOptions. Options& clOptions = *(this->ClOptions[configName]); clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ", - "\n", "ASM_NASM"); + "ASM_NASM"); this->WriteString("\n", 2); } diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h index 87f735d..7106737 100644 --- a/Source/cmVisualStudio10TargetGenerator.h +++ b/Source/cmVisualStudio10TargetGenerator.h @@ -34,8 +34,7 @@ public: void Generate(); // used by cmVisualStudioGeneratorOptions void WritePlatformConfigTag(const char* tag, const std::string& config, - int indentLevel, const char* attribute = 0, - const char* end = 0, std::ostream* strm = 0); + int indentLevel, const char* attribute = 0); private: struct ToolSource diff --git a/Source/cmVisualStudioGeneratorOptions.cxx b/Source/cmVisualStudioGeneratorOptions.cxx index 26fce4b..8b6f057 100644 --- a/Source/cmVisualStudioGeneratorOptions.cxx +++ b/Source/cmVisualStudioGeneratorOptions.cxx @@ -422,8 +422,7 @@ const std::string& cmVisualStudioGeneratorOptions::GetConfiguration() const } void cmVisualStudioGeneratorOptions::OutputPreprocessorDefinitions( - std::ostream& fout, const char* prefix, const char* suffix, - const std::string& lang) + std::ostream& fout, const char* prefix, const std::string& lang) { if (this->Defines.empty()) { return; @@ -462,12 +461,10 @@ void cmVisualStudioGeneratorOptions::OutputPreprocessorDefinitions( } this->OutputFlag(fout, prefix, tag, oss.str()); - fout << suffix; } void cmVisualStudioGeneratorOptions::OutputAdditionalIncludeDirectories( - std::ostream& fout, const char* prefix, const char* suffix, - const std::string& lang) + std::ostream& fout, const char* prefix, const std::string& lang) { if (this->Includes.empty()) { return; @@ -512,7 +509,6 @@ void cmVisualStudioGeneratorOptions::OutputAdditionalIncludeDirectories( } this->OutputFlag(fout, prefix, tag, oss.str()); - fout << suffix; } void cmVisualStudioGeneratorOptions::OutputFlagMap(std::ostream& fout, @@ -530,6 +526,5 @@ void cmVisualStudioGeneratorOptions::OutputFlagMap(std::ostream& fout, } this->OutputFlag(fout, indent, m.first.c_str(), oss.str()); - fout << "\n"; } } diff --git a/Source/cmVisualStudioGeneratorOptions.h b/Source/cmVisualStudioGeneratorOptions.h index 40290d1..974ca62 100644 --- a/Source/cmVisualStudioGeneratorOptions.h +++ b/Source/cmVisualStudioGeneratorOptions.h @@ -78,11 +78,9 @@ public: bool IsManaged() const; // Write options to output. void OutputPreprocessorDefinitions(std::ostream& fout, const char* prefix, - const char* suffix, const std::string& lang); void OutputAdditionalIncludeDirectories(std::ostream& fout, const char* prefix, - const char* suffix, const std::string& lang); void OutputFlagMap(std::ostream& fout, const char* indent); void SetConfiguration(const std::string& config); -- cgit v0.12