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

Method WriteMakeRule

Source/cmLocalUnixMakefileGenerator3.cxx:569–643  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

567}
568
569void cmLocalUnixMakefileGenerator3::WriteMakeRule(
570 std::ostream& os, char const* comment, std::string const& target,
571 std::vector<std::string> const& depends,
572 std::vector<std::string> const& commands, bool symbolic, bool in_help)
573{
574 // Make sure there is a target.
575 if (target.empty()) {
576 std::string err("No target for WriteMakeRule! called with comment: ");
577 if (comment) {
578 err += comment;
579 }
580 cmSystemTools::Error(err);
581 return;
582 }
583
584 std::string replace;
585
586 // Write the comment describing the rule in the makefile.
587 if (comment) {
588 replace = comment;
589 std::string::size_type lpos = 0;
590 std::string::size_type rpos;
591 while ((rpos = replace.find('\n', lpos)) != std::string::npos) {
592 os << "# " << replace.substr(lpos, rpos - lpos) << "\n";
593 lpos = rpos + 1;
594 }
595 os << "# " << replace.substr(lpos) << "\n";
596 }
597
598 // Construct the left hand side of the rule.
599 std::string tgt =
600 this->ConvertToMakefilePath(this->MaybeRelativeToTopBinDir(target));
601
602 char const* space = "";
603 if (tgt.size() == 1) {
604 // Add a space before the ":" to avoid drive letter confusion on
605 // Windows.
606 space = " ";
607 }
608
609 // Mark the rule as symbolic if requested.
610 if (symbolic) {
611 if (cmValue sym =
612 this->Makefile->GetDefinition("CMAKE_MAKE_SYMBOLIC_RULE")) {
613 os << tgt << space << ": " << *sym << '\n';
614 }
615 }
616
617 // Write the rule.
618 if (depends.empty()) {
619 // No dependencies. The commands will always run.
620 os << tgt << space << ":\n";
621 } else {
622 // Split dependencies into multiple rule lines. This allows for
623 // very long dependency lists even on older make implementations.
624 for (std::string const& depend : depends) {
625 os << tgt << space << ": "
626 << this->ConvertToMakefilePath(this->MaybeRelativeToTopBinDir(depend))

Callers 6

WriteConvenienceRuleMethod · 0.95
WriteLocalAllRulesMethod · 0.95

Calls 11

ConvertToMakefilePathMethod · 0.95
cmWrapFunction · 0.85
IsWatcomWMakeMethod · 0.80
push_backMethod · 0.80
ErrorClass · 0.70
emptyMethod · 0.45
findMethod · 0.45
substrMethod · 0.45
sizeMethod · 0.45
GetDefinitionMethod · 0.45

Tested by

no test coverage detected