| 57 | } |
| 58 | |
| 59 | void cmNinjaUtilityTargetGenerator::WriteUtilBuildStatements( |
| 60 | std::string const& config, std::string const& fileConfig) |
| 61 | { |
| 62 | cmGlobalNinjaGenerator* gg = this->GetGlobalGenerator(); |
| 63 | cmLocalNinjaGenerator* lg = this->GetLocalGenerator(); |
| 64 | cmGeneratorTarget* genTarget = this->GetGeneratorTarget(); |
| 65 | |
| 66 | std::string configDir; |
| 67 | if (genTarget->Target->IsPerConfig()) { |
| 68 | configDir = gg->ConfigDirectory(fileConfig); |
| 69 | } |
| 70 | std::string utilCommandName = |
| 71 | cmStrCat(lg->GetCurrentBinaryDirectory(), "/CMakeFiles", configDir, '/', |
| 72 | this->GetTargetName(), ".util"); |
| 73 | utilCommandName = this->ConvertToNinjaPath(utilCommandName); |
| 74 | |
| 75 | cmNinjaBuild phonyBuild("phony"); |
| 76 | std::vector<std::string> commands; |
| 77 | cmNinjaDeps deps; |
| 78 | cmGlobalNinjaGenerator::CCOutputs util_outputs(gg); |
| 79 | util_outputs.ExplicitOuts.emplace_back(utilCommandName); |
| 80 | |
| 81 | std::string commandDesc; |
| 82 | cmGeneratorExpression ge(*this->GetLocalGenerator()->GetCMakeInstance()); |
| 83 | bool uses_terminal = false; |
| 84 | { |
| 85 | std::array<std::vector<cmCustomCommand> const*, 2> const cmdLists = { |
| 86 | { &genTarget->GetPreBuildCommands(), &genTarget->GetPostBuildCommands() } |
| 87 | }; |
| 88 | |
| 89 | for (std::vector<cmCustomCommand> const* cmdList : cmdLists) { |
| 90 | for (cmCustomCommand const& ci : *cmdList) { |
| 91 | cmCustomCommandGenerator ccg(ci, fileConfig, lg); |
| 92 | lg->AppendCustomCommandDeps(ccg, deps, fileConfig); |
| 93 | lg->AppendCustomCommandLines(ccg, commands); |
| 94 | if (ci.GetComment()) { |
| 95 | if (!commandDesc.empty()) { |
| 96 | commandDesc += "; "; |
| 97 | } |
| 98 | auto cge = ge.Parse(ci.GetComment()); |
| 99 | commandDesc += cge->Evaluate(this->GetLocalGenerator(), config); |
| 100 | } |
| 101 | util_outputs.Add(ccg.GetByproducts()); |
| 102 | if (ci.GetUsesTerminal()) { |
| 103 | uses_terminal = true; |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | { |
| 110 | std::vector<cmSourceFile*> sources; |
| 111 | genTarget->GetSourceFiles(sources, config); |
| 112 | for (cmSourceFile const* source : sources) { |
| 113 | if (cmCustomCommand const* cc = source->GetCustomCommand()) { |
| 114 | cmCustomCommandGenerator ccg(*cc, config, lg); |
| 115 | lg->AddCustomCommandTarget(cc, genTarget); |
| 116 |
no test coverage detected