diff options
author | Brad King <brad.king@kitware.com> | 2017-02-16 18:15:52 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2017-02-16 18:15:52 (GMT) |
commit | bb4730dc5add8c5ac54b41efa5375189636429f3 (patch) | |
tree | e7724b3fae21d0328fa434c9ad96b0dca9d5362a | |
parent | 160083b04ddde9904e90cbf8146193e28eb58124 (diff) | |
parent | 109b8a6fd32be9886de71f98170e0c512ac9883f (diff) | |
download | CMake-bb4730dc5add8c5ac54b41efa5375189636429f3.zip CMake-bb4730dc5add8c5ac54b41efa5375189636429f3.tar.gz CMake-bb4730dc5add8c5ac54b41efa5375189636429f3.tar.bz2 |
Merge topic 'vs-refactor-unknown-flags'
109b8a6f VS: Refactor AdditionalOptions generation
bd5ea699 cmVisualStudioGeneratorOptions: Add PrependInerhitedString method
3936a288 cmIDEOptions: Add SpaceAppendable flag table type
-rw-r--r-- | Source/cmIDEFlagTable.h | 3 | ||||
-rw-r--r-- | Source/cmIDEOptions.cxx | 8 | ||||
-rw-r--r-- | Source/cmIDEOptions.h | 14 | ||||
-rw-r--r-- | Source/cmLocalVisualStudio7Generator.cxx | 4 | ||||
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.cxx | 14 | ||||
-rw-r--r-- | Source/cmVisualStudioGeneratorOptions.cxx | 38 | ||||
-rw-r--r-- | Source/cmVisualStudioGeneratorOptions.h | 4 |
7 files changed, 44 insertions, 41 deletions
diff --git a/Source/cmIDEFlagTable.h b/Source/cmIDEFlagTable.h index 64ade76..152e293 100644 --- a/Source/cmIDEFlagTable.h +++ b/Source/cmIDEFlagTable.h @@ -24,6 +24,9 @@ struct cmIDEFlagTable // IgnoreDefaultLibraryNames) UserFollowing = (1 << 5), // expect value in following argument CaseInsensitive = (1 << 6), // flag may be any case + SpaceAppendable = (1 << 7), // a flag that if specified multiple times + // should have its value appended to the + // old value with spaces UserValueIgnored = UserValue | UserIgnored, UserValueRequired = UserValue | UserRequired diff --git a/Source/cmIDEOptions.cxx b/Source/cmIDEOptions.cxx index c6c0e05..1c0a99e 100644 --- a/Source/cmIDEOptions.cxx +++ b/Source/cmIDEOptions.cxx @@ -125,6 +125,8 @@ void cmIDEOptions::FlagMapUpdate(cmIDEFlagTable const* entry, this->FlagMap[entry->IDEName] = entry->value; } else if (entry->special & cmIDEFlagTable::SemicolonAppendable) { this->FlagMap[entry->IDEName].push_back(new_value); + } else if (entry->special & cmIDEFlagTable::SpaceAppendable) { + this->FlagMap[entry->IDEName].append_with_space(new_value); } else { // Use the user-specified value. this->FlagMap[entry->IDEName] = new_value; @@ -172,6 +174,12 @@ void cmIDEOptions::AppendFlag(std::string const& flag, std::copy(value.begin(), value.end(), std::back_inserter(fv)); } +void cmIDEOptions::AppendFlagString(std::string const& flag, + std::string const& value) +{ + this->FlagMap[flag].append_with_space(value); +} + void cmIDEOptions::RemoveFlag(const char* flag) { this->FlagMap.erase(flag); diff --git a/Source/cmIDEOptions.h b/Source/cmIDEOptions.h index a0696e1..465cf2c 100644 --- a/Source/cmIDEOptions.h +++ b/Source/cmIDEOptions.h @@ -29,6 +29,7 @@ public: void AppendFlag(std::string const& flag, std::string const& value); void AppendFlag(std::string const& flag, std::vector<std::string> const& value); + void AppendFlagString(std::string const& flag, std::string const& value); void RemoveFlag(const char* flag); bool HasFlag(std::string const& flag) const; const char* GetFlag(const char* flag); @@ -57,15 +58,22 @@ protected: this->derived::operator=(r); return *this; } + FlagValue& append_with_space(std::string const& r) + { + this->resize(1); + std::string& l = this->operator[](0); + if (!l.empty()) { + l += " "; + } + l += r; + return *this; + } }; std::map<std::string, FlagValue> FlagMap; // Preprocessor definitions. std::vector<std::string> Defines; - // Unrecognized flags that get no special handling. - std::string FlagString; - bool DoingDefine; bool AllowDefine; bool AllowSlash; diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 38dda04..6e976e1 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -787,7 +787,6 @@ void cmLocalVisualStudio7Generator::WriteConfiguration( << this->ConvertToXMLOutputPath(modDir.c_str()) << "\\$(ConfigurationName)\"\n"; } - targetOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n"); fout << "\t\t\t\tAdditionalIncludeDirectories=\""; std::vector<std::string> includes; this->GetIncludeDirectories(includes, target, "C", configName); @@ -1090,7 +1089,6 @@ void cmLocalVisualStudio7Generator::OutputBuildTool( if (!gg->NeedLinkLibraryDependencies(target)) { fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n"; } - linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n"); // Use the NOINHERIT macro to avoid getting VS project default // libraries which may be set by the user to something bad. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) " @@ -1176,7 +1174,6 @@ void cmLocalVisualStudio7Generator::OutputBuildTool( if (!gg->NeedLinkLibraryDependencies(target)) { fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n"; } - linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n"); // Use the NOINHERIT macro to avoid getting VS project default // libraries which may be set by the user to something bad. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) " @@ -1675,7 +1672,6 @@ bool cmLocalVisualStudio7Generator::WriteGroup( fileOptions.Parse(fc.CompileFlags.c_str()); fileOptions.AddDefines(fc.CompileDefs.c_str()); fileOptions.AddDefines(fc.CompileDefsConfig.c_str()); - fileOptions.OutputAdditionalOptions(fout, "\t\t\t\t\t", "\n"); fileOptions.OutputFlagMap(fout, "\t\t\t\t\t"); fileOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t\t", "\n", ppLang); diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index f084e19..e3853ed 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -1939,7 +1939,7 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( } clOptions.AddDefines(configDefines.c_str()); clOptions.SetConfiguration((*config).c_str()); - clOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", ""); + clOptions.PrependInheritedString("AdditionalOptions"); clOptions.OutputFlagMap(*this->BuildFileStream, " "); clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ", "\n", lang); @@ -2293,7 +2293,7 @@ void cmVisualStudio10TargetGenerator::WriteClOptions( return; } this->WriteString("<ClCompile>\n", 2); - clOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", ""); + clOptions.PrependInheritedString("AdditionalOptions"); clOptions.AppendFlag("AdditionalIncludeDirectories", includes); clOptions.AppendFlag("AdditionalIncludeDirectories", "%(AdditionalIncludeDirectories)"); @@ -2395,8 +2395,8 @@ void cmVisualStudio10TargetGenerator::WriteRCOptions( rcOptions.AppendFlag("AdditionalIncludeDirectories", includes); rcOptions.AppendFlag("AdditionalIncludeDirectories", "%(AdditionalIncludeDirectories)"); + rcOptions.PrependInheritedString("AdditionalOptions"); rcOptions.OutputFlagMap(*this->BuildFileStream, " "); - rcOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", ""); this->WriteString("</ResourceCompile>\n", 2); } @@ -2453,8 +2453,8 @@ void cmVisualStudio10TargetGenerator::WriteMasmOptions( Options& masmOptions = *(this->MasmOptions[configName]); masmOptions.AppendFlag("IncludePaths", includes); masmOptions.AppendFlag("IncludePaths", "%(IncludePaths)"); + masmOptions.PrependInheritedString("AdditionalOptions"); masmOptions.OutputFlagMap(*this->BuildFileStream, " "); - masmOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", ""); this->WriteString("</MASM>\n", 2); } @@ -2512,7 +2512,7 @@ void cmVisualStudio10TargetGenerator::WriteNasmOptions( nasmOptions.AppendFlag("IncludePaths", includes); nasmOptions.AppendFlag("IncludePaths", "%(IncludePaths)"); nasmOptions.OutputFlagMap(*this->BuildFileStream, " "); - nasmOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", ""); + nasmOptions.PrependInheritedString("AdditionalOptions"); nasmOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ", "\n", "ASM_NASM"); @@ -2542,7 +2542,7 @@ void cmVisualStudio10TargetGenerator::WriteLibOptions( this->LocalGenerator, cmVisualStudioGeneratorOptions::Linker, gg->GetLibFlagTable(), 0, this); libOptions.Parse(libflags.c_str()); - libOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", ""); + libOptions.PrependInheritedString("AdditionalOptions"); libOptions.OutputFlagMap(*this->BuildFileStream, " "); this->WriteString("</Lib>\n", 2); } @@ -3019,7 +3019,7 @@ void cmVisualStudio10TargetGenerator::WriteLinkOptions( Options& linkOptions = *(this->LinkOptions[config]); this->WriteString("<Link>\n", 2); - linkOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", ""); + linkOptions.PrependInheritedString("AdditionalOptions"); linkOptions.OutputFlagMap(*this->BuildFileStream, " "); this->WriteString("</Link>\n", 2); diff --git a/Source/cmVisualStudioGeneratorOptions.cxx b/Source/cmVisualStudioGeneratorOptions.cxx index 6bacfa1..dfe5ce6 100644 --- a/Source/cmVisualStudioGeneratorOptions.cxx +++ b/Source/cmVisualStudioGeneratorOptions.cxx @@ -211,6 +211,17 @@ void cmVisualStudioGeneratorOptions::ParseFinish() } } +void cmVisualStudioGeneratorOptions::PrependInheritedString( + std::string const& key) +{ + std::map<std::string, FlagValue>::iterator i = this->FlagMap.find(key); + if (i == this->FlagMap.end() || i->second.size() != 1) { + return; + } + std::string& value = i->second[0]; + value = "%(" + key + ") " + value; +} + void cmVisualStudioGeneratorOptions::StoreUnknownFlag(const char* flag) { // Look for Intel Fortran flags that do not map well in the flag table. @@ -234,10 +245,10 @@ void cmVisualStudioGeneratorOptions::StoreUnknownFlag(const char* flag) } // This option is not known. Store it in the output flags. - this->FlagString += " "; - this->FlagString += cmOutputConverter::EscapeWindowsShellArgument( + std::string const opts = cmOutputConverter::EscapeWindowsShellArgument( flag, cmOutputConverter::Shell_Flag_AllowMakeVariables | cmOutputConverter::Shell_Flag_VSIDE); + this->AppendFlagString("AdditionalOptions", opts); } void cmVisualStudioGeneratorOptions::SetConfiguration(const char* config) @@ -332,26 +343,3 @@ void cmVisualStudioGeneratorOptions::OutputFlagMap(std::ostream& fout, } } } - -void cmVisualStudioGeneratorOptions::OutputAdditionalOptions( - std::ostream& fout, const char* prefix, const char* suffix) -{ - if (!this->FlagString.empty()) { - if (this->Version >= cmGlobalVisualStudioGenerator::VS10) { - fout << prefix; - if (!this->Configuration.empty()) { - this->TargetGenerator->WritePlatformConfigTag( - "AdditionalOptions", this->Configuration.c_str(), 0, 0, 0, &fout); - } else { - fout << "<AdditionalOptions>"; - } - fout << "%(AdditionalOptions) " - << cmVisualStudio10GeneratorOptionsEscapeForXML(this->FlagString) - << "</AdditionalOptions>\n"; - } else { - fout << prefix << "AdditionalOptions=\""; - fout << cmVisualStudioGeneratorOptionsEscapeForXML(this->FlagString); - fout << "\"" << suffix; - } - } -} diff --git a/Source/cmVisualStudioGeneratorOptions.h b/Source/cmVisualStudioGeneratorOptions.h index 3a53ff5..8c49470 100644 --- a/Source/cmVisualStudioGeneratorOptions.h +++ b/Source/cmVisualStudioGeneratorOptions.h @@ -47,6 +47,8 @@ public: void Parse(const char* flags); void ParseFinish(); + void PrependInheritedString(std::string const& key); + // Fix the ExceptionHandling option to default to off. void FixExceptionHandlingDefault(); @@ -65,8 +67,6 @@ public: const char* suffix, const std::string& lang); void OutputFlagMap(std::ostream& fout, const char* indent); - void OutputAdditionalOptions(std::ostream& fout, const char* prefix, - const char* suffix); void SetConfiguration(const char* config); private: |