| 500 | } |
| 501 | |
| 502 | void cmGlobalNinjaGenerator::WriteVariable(std::ostream& os, |
| 503 | std::string const& name, |
| 504 | std::string const& value, |
| 505 | std::string const& comment, |
| 506 | int indent) |
| 507 | { |
| 508 | // Make sure we have a name. |
| 509 | if (name.empty()) { |
| 510 | cmSystemTools::Error(cmStrCat("No name given for WriteVariable! called " |
| 511 | "with comment: ", |
| 512 | comment)); |
| 513 | return; |
| 514 | } |
| 515 | |
| 516 | std::string val; |
| 517 | static std::unordered_set<std::string> const variablesShouldNotBeTrimmed = { |
| 518 | "CODE_CHECK", "LAUNCHER" |
| 519 | }; |
| 520 | if (variablesShouldNotBeTrimmed.find(name) == |
| 521 | variablesShouldNotBeTrimmed.end()) { |
| 522 | val = cmTrimWhitespace(value); |
| 523 | // If the value ends with `\n` and a `$` was left at the end of the trimmed |
| 524 | // value, put the newline back. Otherwise the next stanza is hidden by the |
| 525 | // trailing `$` escaping the newline. |
| 526 | if (cmSystemTools::StringEndsWith(value, "\n") && |
| 527 | cmSystemTools::StringEndsWith(val, "$")) { |
| 528 | val += '\n'; |
| 529 | } |
| 530 | } else { |
| 531 | val = value; |
| 532 | } |
| 533 | |
| 534 | // Do not add a variable if the value is empty. |
| 535 | if (val.empty()) { |
| 536 | return; |
| 537 | } |
| 538 | |
| 539 | cmGlobalNinjaGenerator::WriteComment(os, comment); |
| 540 | cmGlobalNinjaGenerator::Indent(os, indent); |
| 541 | os << name << " = " << val << "\n"; |
| 542 | } |
| 543 | |
| 544 | void cmGlobalNinjaGenerator::WriteInclude(std::ostream& os, |
| 545 | std::string const& filename, |