diff options
author | Marc Chevrier <marc.chevrier@sap.com> | 2017-12-15 10:00:52 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@sap.com> | 2018-01-23 09:24:47 (GMT) |
commit | 3f935e690a337a7a692c30d4d14082e08d1bed7c (patch) | |
tree | 737bdc0cc2a6eb04366e84ebfd2d48f7fdde68d9 | |
parent | 2c6f5baaa7e101cdd3e5769a3fd8d49d0501b8e6 (diff) | |
download | CMake-3f935e690a337a7a692c30d4d14082e08d1bed7c.zip CMake-3f935e690a337a7a692c30d4d14082e08d1bed7c.tar.gz CMake-3f935e690a337a7a692c30d4d14082e08d1bed7c.tar.bz2 |
LocalGenerator: refactoring
Introduce method AppendCompileOptions to support
future source file property COMPILE_OPTIONS.
-rw-r--r-- | Source/cmGlobalXCodeGenerator.cxx | 2 | ||||
-rw-r--r-- | Source/cmGlobalXCodeGenerator.h | 2 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 59 | ||||
-rw-r--r-- | Source/cmLocalGenerator.h | 23 | ||||
-rw-r--r-- | Source/cmLocalUnixMakefileGenerator3.cxx | 6 | ||||
-rw-r--r-- | Source/cmLocalUnixMakefileGenerator3.h | 5 | ||||
-rw-r--r-- | Source/cmLocalXCodeGenerator.cxx | 6 | ||||
-rw-r--r-- | Source/cmLocalXCodeGenerator.h | 2 |
8 files changed, 76 insertions, 29 deletions
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index bd51f60..c34143e 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -3521,7 +3521,7 @@ void cmGlobalXCodeGenerator::AppendDefines( } void cmGlobalXCodeGenerator::AppendFlag(std::string& flags, - std::string const& flag) + std::string const& flag) const { // Short-circuit for an empty flag. if (flag.empty()) { diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h index 2269b25..d173f7a 100644 --- a/Source/cmGlobalXCodeGenerator.h +++ b/Source/cmGlobalXCodeGenerator.h @@ -104,7 +104,7 @@ public: bool ShouldStripResourcePath(cmMakefile*) const override; bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf) override; - void AppendFlag(std::string& flags, std::string const& flag); + void AppendFlag(std::string& flags, std::string const& flag) const; protected: void AddExtraIDETargets() override; diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index c8d94c0..d918cf3 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -792,19 +792,14 @@ void cmLocalGenerator::AddCompileOptions(std::string& flags, if (const char* langFlagRegexStr = this->Makefile->GetDefinition(langFlagRegexVar)) { // Filter flags acceptable to this language. - cmsys::RegularExpression r(langFlagRegexStr); std::vector<std::string> opts; if (const char* targetFlags = target->GetProperty("COMPILE_FLAGS")) { cmSystemTools::ParseWindowsCommandLine(targetFlags, opts); } target->GetCompileOptions(opts, config, lang); - for (std::string const& opt : opts) { - if (r.find(opt.c_str())) { - // (Re-)Escape this flag. COMPILE_FLAGS were already parsed - // as a command line above, and COMPILE_OPTIONS are escaped. - this->AppendFlagEscape(flags, opt); - } - } + // (Re-)Escape these flags. COMPILE_FLAGS were already parsed + // as a command line above, and COMPILE_OPTIONS are escaped. + this->AppendCompileOptions(flags, opts, langFlagRegexStr); } else { // Use all flags. if (const char* targetFlags = target->GetProperty("COMPILE_FLAGS")) { @@ -813,10 +808,8 @@ void cmLocalGenerator::AddCompileOptions(std::string& flags, } std::vector<std::string> opts; target->GetCompileOptions(opts, config, lang); - for (std::string const& opt : opts) { - // COMPILE_OPTIONS are escaped. - this->AppendFlagEscape(flags, opt); - } + // COMPILE_OPTIONS are escaped. + this->AppendCompileOptions(flags, opts); } for (auto const& it : target->GetMaxLanguageStandards()) { @@ -1876,7 +1869,7 @@ void cmLocalGenerator::AddConfigVariableFlags(std::string& flags, } void cmLocalGenerator::AppendFlags(std::string& flags, - const std::string& newFlags) + const std::string& newFlags) const { if (!newFlags.empty()) { if (!flags.empty()) { @@ -1886,7 +1879,8 @@ void cmLocalGenerator::AppendFlags(std::string& flags, } } -void cmLocalGenerator::AppendFlags(std::string& flags, const char* newFlags) +void cmLocalGenerator::AppendFlags(std::string& flags, + const char* newFlags) const { if (newFlags && *newFlags) { this->AppendFlags(flags, std::string(newFlags)); @@ -1894,7 +1888,7 @@ void cmLocalGenerator::AppendFlags(std::string& flags, const char* newFlags) } void cmLocalGenerator::AppendFlagEscape(std::string& flags, - const std::string& rawFlag) + const std::string& rawFlag) const { this->AppendFlags(flags, this->EscapeForShell(rawFlag)); } @@ -1930,6 +1924,41 @@ void cmLocalGenerator::AppendIPOLinkerFlags(std::string& flags, } } +void cmLocalGenerator::AppendCompileOptions(std::string& options, + const char* options_list, + const char* regex) const +{ + // Short-circuit if there are no options. + if (!options_list) { + return; + } + + // Expand the list of options. + std::vector<std::string> options_vec; + cmSystemTools::ExpandListArgument(options_list, options_vec); + this->AppendCompileOptions(options, options_vec, regex); +} + +void cmLocalGenerator::AppendCompileOptions( + std::string& options, const std::vector<std::string>& options_vec, + const char* regex) const +{ + if (regex != nullptr) { + // Filter flags upon specified reges. + cmsys::RegularExpression r(regex); + + for (std::string const& opt : options_vec) { + if (r.find(opt.c_str())) { + this->AppendFlagEscape(options, opt); + } + } + } else { + for (std::string const& opt : options_vec) { + this->AppendFlagEscape(options, opt); + } + } +} + void cmLocalGenerator::AppendDefines(std::set<std::string>& defines, const char* defines_list) const { diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 4a7d2ca..b993967 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -118,10 +118,11 @@ public: cmGeneratorTarget const* target, const std::string& lang); ///! Append flags to a string. - virtual void AppendFlags(std::string& flags, const std::string& newFlags); - virtual void AppendFlags(std::string& flags, const char* newFlags); + virtual void AppendFlags(std::string& flags, + const std::string& newFlags) const; + virtual void AppendFlags(std::string& flags, const char* newFlags) const; virtual void AppendFlagEscape(std::string& flags, - const std::string& rawFlag); + const std::string& rawFlag) const; void AppendIPOLinkerFlags(std::string& flags, cmGeneratorTarget* target, const std::string& config, const std::string& lang); @@ -166,6 +167,22 @@ public: const std::vector<std::string>& defines_vec) const; /** + * Encode a list of compile options for the compiler + * command line. + */ + void AppendCompileOptions(std::string& options, const char* options_list, + const char* regex = nullptr) const; + void AppendCompileOptions(std::string& options, + std::string const& options_list, + const char* regex = nullptr) const + { + this->AppendCompileOptions(options, options_list.c_str(), regex); + } + void AppendCompileOptions(std::string& options, + const std::vector<std::string>& options_vec, + const char* regex = nullptr) const; + + /** * Join a set of defines into a definesString with a space separator. */ void JoinDefines(const std::set<std::string>& defines, diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 28890f0..e2d5322 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -830,8 +830,8 @@ std::string cmLocalUnixMakefileGenerator3::GetRelativeTargetDirectory( return dir; } -void cmLocalUnixMakefileGenerator3::AppendFlags(std::string& flags, - const std::string& newFlags) +void cmLocalUnixMakefileGenerator3::AppendFlags( + std::string& flags, const std::string& newFlags) const { if (this->IsWatcomWMake() && !newFlags.empty()) { std::string newf = newFlags; @@ -845,7 +845,7 @@ void cmLocalUnixMakefileGenerator3::AppendFlags(std::string& flags, } void cmLocalUnixMakefileGenerator3::AppendFlags(std::string& flags, - const char* newFlags) + const char* newFlags) const { this->cmLocalGenerator::AppendFlags(flags, newFlags); } diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h index b149524..86c5aab 100644 --- a/Source/cmLocalUnixMakefileGenerator3.h +++ b/Source/cmLocalUnixMakefileGenerator3.h @@ -88,8 +88,9 @@ public: const std::string& tgt); // append flags to a string - void AppendFlags(std::string& flags, const std::string& newFlags) override; - void AppendFlags(std::string& flags, const char* newFlags) override; + void AppendFlags(std::string& flags, + const std::string& newFlags) const override; + void AppendFlags(std::string& flags, const char* newFlags) const override; // append an echo command enum EchoColor diff --git a/Source/cmLocalXCodeGenerator.cxx b/Source/cmLocalXCodeGenerator.cxx index 457d1fd..92c958d 100644 --- a/Source/cmLocalXCodeGenerator.cxx +++ b/Source/cmLocalXCodeGenerator.cxx @@ -31,10 +31,10 @@ std::string cmLocalXCodeGenerator::GetTargetDirectory( } void cmLocalXCodeGenerator::AppendFlagEscape(std::string& flags, - const std::string& rawFlag) + const std::string& rawFlag) const { - cmGlobalXCodeGenerator* gg = - static_cast<cmGlobalXCodeGenerator*>(this->GlobalGenerator); + const cmGlobalXCodeGenerator* gg = + static_cast<const cmGlobalXCodeGenerator*>(this->GlobalGenerator); gg->AppendFlag(flags, rawFlag); } diff --git a/Source/cmLocalXCodeGenerator.h b/Source/cmLocalXCodeGenerator.h index 8c9596f..5c22dcf 100644 --- a/Source/cmLocalXCodeGenerator.h +++ b/Source/cmLocalXCodeGenerator.h @@ -31,7 +31,7 @@ public: std::string GetTargetDirectory( cmGeneratorTarget const* target) const override; void AppendFlagEscape(std::string& flags, - const std::string& rawFlag) override; + const std::string& rawFlag) const override; void Generate() override; virtual void GenerateInstallRules(); void ComputeObjectFilenames( |