MCPcopy Create free account
hub / github.com/Kitware/CMake / WriteVariable

Method WriteVariable

Source/cmGlobalNinjaGenerator.cxx:502–542  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

500}
501
502void 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
544void cmGlobalNinjaGenerator::WriteInclude(std::ostream& os,
545 std::string const& filename,

Callers

nothing calls this directly

Calls 6

cmTrimWhitespaceFunction · 0.85
ErrorClass · 0.70
cmStrCatFunction · 0.70
emptyMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected