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

Method GetCustomCommandTarget

Source/cmMakefile.cxx:1087–1138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1085}
1086
1087cmTarget* cmMakefile::GetCustomCommandTarget(
1088 std::string const& target, cmObjectLibraryCommands objLibCommands,
1089 cmListFileBacktrace const& lfbt) const
1090{
1091 auto realTarget = target;
1092
1093 auto ai = this->AliasTargets.find(target);
1094 if (ai != this->AliasTargets.end()) {
1095 realTarget = ai->second;
1096 }
1097
1098 // Find the target to which to add the custom command.
1099 auto ti = this->Targets.find(realTarget);
1100 if (ti == this->Targets.end()) {
1101 std::string e;
1102 if (cmTarget const* t = this->FindTargetToUse(target)) {
1103 if (t->IsImported()) {
1104 e += cmStrCat("TARGET '", target,
1105 "' is IMPORTED and does not build here.");
1106 } else {
1107 e +=
1108 cmStrCat("TARGET '", target, "' was not created in this directory.");
1109 }
1110 } else {
1111 e += cmStrCat("No TARGET '", target,
1112 "' has been created in this directory.");
1113 }
1114 this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, e, lfbt);
1115 return nullptr;
1116 }
1117
1118 cmTarget* t = &ti->second;
1119 if (objLibCommands == cmObjectLibraryCommands::Reject &&
1120 t->GetType() == cmStateEnums::OBJECT_LIBRARY) {
1121 auto e = cmStrCat(
1122 "Target \"", target,
1123 "\" is an OBJECT library "
1124 "that may not have PRE_BUILD, PRE_LINK, or POST_BUILD commands.");
1125 this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, e, lfbt);
1126 return nullptr;
1127 }
1128 if (t->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
1129 auto e = cmStrCat(
1130 "Target \"", target,
1131 "\" is an INTERFACE library "
1132 "that may not have PRE_BUILD, PRE_LINK, or POST_BUILD commands.");
1133 this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, e, lfbt);
1134 return nullptr;
1135 }
1136
1137 return t;
1138}
1139
1140cmTarget* cmMakefile::AddCustomCommandToTarget(
1141 std::string const& target, cmCustomCommandType type,

Callers 2

Calls 8

FindTargetToUseMethod · 0.95
GetCMakeInstanceMethod · 0.95
cmStrCatFunction · 0.70
findMethod · 0.45
endMethod · 0.45
IsImportedMethod · 0.45
IssueMessageMethod · 0.45
GetTypeMethod · 0.45

Tested by

no test coverage detected