summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2020-03-23 17:02:11 (GMT)
committerDaan De Meyer <daan.j.demeyer@gmail.com>2020-03-23 20:34:19 (GMT)
commit5d4bab500e93052630163577815695ac3f47ba7b (patch)
treece08a20d9e4a6cddf8f843c9f8e5c49eecb69781 /Source
parentd8622fbd0fe1ad7db1e22089464342f329426e9e (diff)
downloadCMake-5d4bab500e93052630163577815695ac3f47ba7b.zip
CMake-5d4bab500e93052630163577815695ac3f47ba7b.tar.gz
CMake-5d4bab500e93052630163577815695ac3f47ba7b.tar.bz2
Avoid consecutive whitespace in rules
Diffstat (limited to 'Source')
-rw-r--r--Source/cmLocalGenerator.cxx6
-rw-r--r--Source/cmRulePlaceholderExpander.cxx10
2 files changed, 14 insertions, 2 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index a7799b6..62b8052 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -877,7 +877,7 @@ std::string cmLocalGenerator::GetIncludeFlags(
if ((sep[0] != ' ') && !flags.empty() && flags.back() == sep[0]) {
flags.back() = ' ';
}
- return flags;
+ return cmTrimWhitespace(flags);
}
void cmLocalGenerator::AddCompileOptions(std::string& flags,
@@ -2396,7 +2396,9 @@ void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
void cmLocalGenerator::AppendFlags(std::string& flags,
const std::string& newFlags) const
{
- if (!newFlags.empty()) {
+ bool allSpaces = std::all_of(newFlags.begin(), newFlags.end(), cmIsSpace);
+
+ if (!newFlags.empty() && !allSpaces) {
if (!flags.empty()) {
flags += " ";
}
diff --git a/Source/cmRulePlaceholderExpander.cxx b/Source/cmRulePlaceholderExpander.cxx
index 5ab1b3a..99b0d5c 100644
--- a/Source/cmRulePlaceholderExpander.cxx
+++ b/Source/cmRulePlaceholderExpander.cxx
@@ -334,7 +334,17 @@ void cmRulePlaceholderExpander::ExpandRuleVariables(
std::string replace =
this->ExpandRuleVariable(outputConverter, var, replaceValues);
expandedInput += s.substr(pos, start - pos);
+
+ // Prevent consecutive whitespace in the output if the rule variable
+ // expands to an empty string.
+ bool consecutive = replace.empty() && start > 0 && s[start - 1] == ' ' &&
+ end + 1 < s.size() && s[end + 1] == ' ';
+ if (consecutive) {
+ expandedInput.pop_back();
+ }
+
expandedInput += replace;
+
// move to next one
start = s.find('<', start + var.size() + 2);
pos = end + 1;