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

Method WriteCustomCommandBuild

Source/cmGlobalNinjaGenerator.cxx:352–411  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

350}
351
352void cmGlobalNinjaGenerator::WriteCustomCommandBuild(
353 std::string const& command, std::string const& description,
354 std::string const& comment, std::string const& depfile,
355 std::string const& job_pool, bool uses_terminal, bool restat,
356 std::string const& config, CCOutputs outputs, cmNinjaDeps explicitDeps,
357 cmNinjaDeps orderOnlyDeps)
358{
359 this->AddCustomCommandRule();
360
361 {
362 std::string ninjaDepfilePath;
363 bool depfileIsOutput = false;
364 if (!depfile.empty()) {
365 ninjaDepfilePath = this->ConvertToNinjaPath(depfile);
366 depfileIsOutput =
367 std::find(outputs.ExplicitOuts.begin(), outputs.ExplicitOuts.end(),
368 ninjaDepfilePath) != outputs.ExplicitOuts.end();
369 }
370
371 cmNinjaBuild build("CUSTOM_COMMAND");
372 build.Comment = comment;
373 build.Outputs = std::move(outputs.ExplicitOuts);
374 build.WorkDirOuts = std::move(outputs.WorkDirOuts);
375 build.ExplicitDeps = std::move(explicitDeps);
376 build.OrderOnlyDeps = std::move(orderOnlyDeps);
377
378 cmNinjaVars& vars = build.Variables;
379 {
380 std::string cmd = command; // NOLINT(*)
381#ifdef _WIN32
382 if (cmd.empty())
383 cmd = "cmd.exe /c";
384#endif
385 vars["COMMAND"] = std::move(cmd);
386 }
387 vars["DESC"] = this->GetEncodedLiteral(description);
388 if (restat) {
389 vars["restat"] = "1";
390 }
391 if (uses_terminal && this->SupportsDirectConsole()) {
392 vars["pool"] = "console";
393 } else if (!job_pool.empty()) {
394 vars["pool"] = job_pool;
395 }
396 if (!depfile.empty()) {
397 vars["depfile"] = ninjaDepfilePath;
398 // Add the depfile to the `.ninja_deps` database. Since this (generally)
399 // removes the file, it cannot be declared as an output or byproduct of
400 // the command.
401 if (!depfileIsOutput) {
402 vars["deps"] = "gcc";
403 }
404 }
405 if (config.empty()) {
406 this->WriteBuild(*this->GetCommonFileStream(), build);
407 } else {
408 this->WriteBuild(*this->GetImplFileStream(config), build);
409 }

Calls 11

AddCustomCommandRuleMethod · 0.95
SupportsDirectConsoleMethod · 0.95
WriteBuildMethod · 0.95
GetCommonFileStreamMethod · 0.95
GetImplFileStreamMethod · 0.95
moveFunction · 0.85
GetEncodedLiteralMethod · 0.80
findFunction · 0.50
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected