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 /Source/cmLocalGenerator.cxx | |
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.
Diffstat (limited to 'Source/cmLocalGenerator.cxx')
-rw-r--r-- | Source/cmLocalGenerator.cxx | 59 |
1 files changed, 44 insertions, 15 deletions
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 { |