| 121 | } // anonymous namespace |
| 122 | |
| 123 | bool cmVariableWatchCommand(std::vector<std::string> const& args, |
| 124 | cmExecutionStatus& status) |
| 125 | { |
| 126 | if (args.empty()) { |
| 127 | status.SetError("must be called with at least one argument."); |
| 128 | return false; |
| 129 | } |
| 130 | std::string const& variable = args[0]; |
| 131 | std::string command; |
| 132 | if (args.size() > 1) { |
| 133 | command = args[1]; |
| 134 | } |
| 135 | if (variable == "CMAKE_CURRENT_LIST_FILE") { |
| 136 | status.SetError(cmStrCat("cannot be set on the variable: ", variable)); |
| 137 | return false; |
| 138 | } |
| 139 | |
| 140 | auto* const data = new cmVariableWatchCallbackData; |
| 141 | |
| 142 | data->InCallback = false; |
| 143 | data->Command = std::move(command); |
| 144 | |
| 145 | if (!status.GetMakefile().GetCMakeInstance()->GetVariableWatch()->AddWatch( |
| 146 | variable, cmVariableWatchCommandVariableAccessed, data, |
| 147 | deleteVariableWatchCallbackData)) { |
| 148 | deleteVariableWatchCallbackData(data); |
| 149 | return false; |
| 150 | } |
| 151 | |
| 152 | status.GetMakefile().AddGeneratorAction( |
| 153 | FinalAction{ &status.GetMakefile(), variable }); |
| 154 | return true; |
| 155 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…