Coverage Report

Created: 2026-04-29 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmAddCustomCommandCommand.cxx
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst or https://cmake.org/licensing for details.  */
3
#include "cmAddCustomCommandCommand.h"
4
5
#include <algorithm>
6
#include <iterator>
7
#include <set>
8
#include <unordered_set>
9
#include <utility>
10
11
#include <cm/memory>
12
#include <cmext/string_view>
13
14
#include "cmCustomCommand.h"
15
#include "cmCustomCommandLines.h"
16
#include "cmCustomCommandTypes.h"
17
#include "cmDiagnostics.h"
18
#include "cmExecutionStatus.h"
19
#include "cmGeneratorExpression.h"
20
#include "cmGlobalGenerator.h"
21
#include "cmMakefile.h"
22
#include "cmMessageType.h"
23
#include "cmPolicies.h"
24
#include "cmStringAlgorithms.h"
25
#include "cmSystemTools.h"
26
#include "cmValue.h"
27
28
bool cmAddCustomCommandCommand(std::vector<std::string> const& args,
29
                               cmExecutionStatus& status)
30
0
{
31
  /* Let's complain at the end of this function about the lack of a particular
32
     arg. For the moment, let's say that COMMAND, and either TARGET or SOURCE
33
     are required.
34
  */
35
0
  if (args.size() < 4) {
36
0
    status.SetError("called with wrong number of arguments.");
37
0
    return false;
38
0
  }
39
40
0
  cmMakefile& mf = status.GetMakefile();
41
0
  std::string source;
42
0
  std::string target;
43
0
  std::string main_dependency;
44
0
  std::string working;
45
0
  std::string depfile;
46
0
  std::string job_pool;
47
0
  std::string job_server_aware;
48
0
  std::string comment_buffer;
49
0
  char const* comment = nullptr;
50
0
  std::vector<std::string> depends;
51
0
  std::vector<std::string> outputs;
52
0
  std::vector<std::string> output;
53
0
  std::vector<std::string> byproducts;
54
0
  bool verbatim = false;
55
0
  bool append = false;
56
0
  bool uses_terminal = false;
57
0
  bool command_expand_lists = false;
58
0
  bool depends_explicit_only =
59
0
    mf.IsOn("CMAKE_ADD_CUSTOM_COMMAND_DEPENDS_EXPLICIT_ONLY");
60
0
  bool codegen = false;
61
0
  std::string implicit_depends_lang;
62
0
  cmImplicitDependsList implicit_depends;
63
64
  // Accumulate one command line at a time.
65
0
  cmCustomCommandLine currentLine;
66
67
  // Save all command lines.
68
0
  cmCustomCommandLines commandLines;
69
70
0
  cmCustomCommandType cctype = cmCustomCommandType::POST_BUILD;
71
72
0
  enum tdoing
73
0
  {
74
0
    doing_source,
75
0
    doing_command,
76
0
    doing_target,
77
0
    doing_depends,
78
0
    doing_implicit_depends_lang,
79
0
    doing_implicit_depends_file,
80
0
    doing_main_dependency,
81
0
    doing_output,
82
0
    doing_outputs,
83
0
    doing_byproducts,
84
0
    doing_comment,
85
0
    doing_working_directory,
86
0
    doing_depfile,
87
0
    doing_job_pool,
88
0
    doing_job_server_aware,
89
0
    doing_nothing
90
0
  };
91
92
0
  tdoing doing = doing_nothing;
93
94
0
#define MAKE_STATIC_KEYWORD(KEYWORD)                                          \
95
0
  static const std::string key##KEYWORD = #KEYWORD
96
0
  MAKE_STATIC_KEYWORD(APPEND);
97
0
  MAKE_STATIC_KEYWORD(ARGS);
98
0
  MAKE_STATIC_KEYWORD(BYPRODUCTS);
99
0
  MAKE_STATIC_KEYWORD(COMMAND);
100
0
  MAKE_STATIC_KEYWORD(COMMAND_EXPAND_LISTS);
101
0
  MAKE_STATIC_KEYWORD(COMMENT);
102
0
  MAKE_STATIC_KEYWORD(DEPENDS);
103
0
  MAKE_STATIC_KEYWORD(DEPFILE);
104
0
  MAKE_STATIC_KEYWORD(IMPLICIT_DEPENDS);
105
0
  MAKE_STATIC_KEYWORD(JOB_POOL);
106
0
  MAKE_STATIC_KEYWORD(JOB_SERVER_AWARE);
107
0
  MAKE_STATIC_KEYWORD(MAIN_DEPENDENCY);
108
0
  MAKE_STATIC_KEYWORD(OUTPUT);
109
0
  MAKE_STATIC_KEYWORD(OUTPUTS);
110
0
  MAKE_STATIC_KEYWORD(POST_BUILD);
111
0
  MAKE_STATIC_KEYWORD(PRE_BUILD);
112
0
  MAKE_STATIC_KEYWORD(PRE_LINK);
113
0
  MAKE_STATIC_KEYWORD(SOURCE);
114
0
  MAKE_STATIC_KEYWORD(TARGET);
115
0
  MAKE_STATIC_KEYWORD(USES_TERMINAL);
116
0
  MAKE_STATIC_KEYWORD(VERBATIM);
117
0
  MAKE_STATIC_KEYWORD(WORKING_DIRECTORY);
118
0
  MAKE_STATIC_KEYWORD(DEPENDS_EXPLICIT_ONLY);
119
0
  MAKE_STATIC_KEYWORD(CODEGEN);
120
0
#undef MAKE_STATIC_KEYWORD
121
0
  static std::unordered_set<std::string> const keywords{
122
0
    keyAPPEND,
123
0
    keyARGS,
124
0
    keyBYPRODUCTS,
125
0
    keyCOMMAND,
126
0
    keyCOMMAND_EXPAND_LISTS,
127
0
    keyCOMMENT,
128
0
    keyDEPENDS,
129
0
    keyDEPFILE,
130
0
    keyIMPLICIT_DEPENDS,
131
0
    keyJOB_POOL,
132
0
    keyMAIN_DEPENDENCY,
133
0
    keyOUTPUT,
134
0
    keyOUTPUTS,
135
0
    keyPOST_BUILD,
136
0
    keyPRE_BUILD,
137
0
    keyPRE_LINK,
138
0
    keySOURCE,
139
0
    keyJOB_SERVER_AWARE,
140
0
    keyTARGET,
141
0
    keyUSES_TERMINAL,
142
0
    keyVERBATIM,
143
0
    keyWORKING_DIRECTORY,
144
0
    keyDEPENDS_EXPLICIT_ONLY,
145
0
    keyCODEGEN
146
0
  };
147
  /* clang-format off */
148
0
  static std::set<std::string> const supportedTargetKeywords{
149
0
    keyARGS,
150
0
    keyBYPRODUCTS,
151
0
    keyCOMMAND,
152
0
    keyCOMMAND_EXPAND_LISTS,
153
0
    keyCOMMENT,
154
0
    keyPOST_BUILD,
155
0
    keyPRE_BUILD,
156
0
    keyPRE_LINK,
157
0
    keyTARGET,
158
0
    keyUSES_TERMINAL,
159
0
    keyVERBATIM,
160
0
    keyWORKING_DIRECTORY
161
0
  };
162
  /* clang-format on */
163
0
  static std::set<std::string> const supportedOutputKeywords{
164
0
    keyAPPEND,
165
0
    keyARGS,
166
0
    keyBYPRODUCTS,
167
0
    keyCODEGEN,
168
0
    keyCOMMAND,
169
0
    keyCOMMAND_EXPAND_LISTS,
170
0
    keyCOMMENT,
171
0
    keyDEPENDS,
172
0
    keyDEPENDS_EXPLICIT_ONLY,
173
0
    keyDEPFILE,
174
0
    keyIMPLICIT_DEPENDS,
175
0
    keyJOB_POOL,
176
0
    keyJOB_SERVER_AWARE,
177
0
    keyMAIN_DEPENDENCY,
178
0
    keyOUTPUT,
179
0
    keyUSES_TERMINAL,
180
0
    keyVERBATIM,
181
0
    keyWORKING_DIRECTORY
182
0
  };
183
  /* clang-format off */
184
0
  static std::set<std::string> const supportedAppendKeywords{
185
0
    keyAPPEND,
186
0
    keyARGS,
187
0
    keyCOMMAND,
188
0
    keyCOMMENT,           // Allowed but ignored
189
0
    keyDEPENDS,
190
0
    keyIMPLICIT_DEPENDS,
191
0
    keyMAIN_DEPENDENCY,   // Allowed but ignored
192
0
    keyOUTPUT,
193
0
    keyWORKING_DIRECTORY  // Allowed but ignored
194
0
  };
195
  /* clang-format on */
196
0
  std::set<std::string> keywordsSeen;
197
0
  std::string const* keywordExpectingValue = nullptr;
198
0
  auto const cmp0175 = mf.GetPolicyStatus(cmPolicies::CMP0175);
199
200
0
  for (std::string const& copy : args) {
201
0
    if (keywords.count(copy)) {
202
      // Check if a preceding keyword expected a value but there wasn't one
203
0
      if (keywordExpectingValue) {
204
0
        std::string const msg =
205
0
          cmStrCat("Keyword ", *keywordExpectingValue,
206
0
                   " requires a value, but none was given.");
207
0
        if (cmp0175 == cmPolicies::NEW) {
208
0
          mf.IssueMessage(MessageType::FATAL_ERROR, msg);
209
0
          return false;
210
0
        }
211
0
        if (cmp0175 == cmPolicies::WARN) {
212
0
          mf.IssueDiagnostic(
213
0
            cmDiagnostics::CMD_AUTHOR,
214
0
            cmStrCat(msg, '\n',
215
0
                     cmPolicies::GetPolicyWarning(cmPolicies::CMP0175)));
216
0
        }
217
0
      }
218
0
      keywordExpectingValue = nullptr;
219
0
      keywordsSeen.insert(copy);
220
221
0
      if (copy == keySOURCE) {
222
0
        doing = doing_source;
223
0
        keywordExpectingValue = &keySOURCE;
224
0
      } else if (copy == keyCOMMAND) {
225
0
        doing = doing_command;
226
227
        // Save the current command before starting the next command.
228
0
        if (!currentLine.empty()) {
229
0
          commandLines.push_back(currentLine);
230
0
          currentLine.clear();
231
0
        }
232
0
      } else if (copy == keyPRE_BUILD) {
233
0
        cctype = cmCustomCommandType::PRE_BUILD;
234
0
      } else if (copy == keyPRE_LINK) {
235
0
        cctype = cmCustomCommandType::PRE_LINK;
236
0
      } else if (copy == keyPOST_BUILD) {
237
0
        cctype = cmCustomCommandType::POST_BUILD;
238
0
      } else if (copy == keyVERBATIM) {
239
0
        verbatim = true;
240
0
      } else if (copy == keyAPPEND) {
241
0
        append = true;
242
0
      } else if (copy == keyUSES_TERMINAL) {
243
0
        uses_terminal = true;
244
0
      } else if (copy == keyCOMMAND_EXPAND_LISTS) {
245
0
        command_expand_lists = true;
246
0
      } else if (copy == keyDEPENDS_EXPLICIT_ONLY) {
247
0
        depends_explicit_only = true;
248
0
      } else if (copy == keyCODEGEN) {
249
0
        codegen = true;
250
0
      } else if (copy == keyTARGET) {
251
0
        doing = doing_target;
252
0
        keywordExpectingValue = &keyTARGET;
253
0
      } else if (copy == keyARGS) {
254
        // Ignore this old keyword.
255
0
      } else if (copy == keyDEPENDS) {
256
0
        doing = doing_depends;
257
0
      } else if (copy == keyOUTPUTS) {
258
0
        doing = doing_outputs;
259
0
      } else if (copy == keyOUTPUT) {
260
0
        doing = doing_output;
261
0
        keywordExpectingValue = &keyOUTPUT;
262
0
      } else if (copy == keyBYPRODUCTS) {
263
0
        doing = doing_byproducts;
264
0
      } else if (copy == keyWORKING_DIRECTORY) {
265
0
        doing = doing_working_directory;
266
0
        keywordExpectingValue = &keyWORKING_DIRECTORY;
267
0
      } else if (copy == keyMAIN_DEPENDENCY) {
268
0
        doing = doing_main_dependency;
269
0
        keywordExpectingValue = &keyMAIN_DEPENDENCY;
270
0
      } else if (copy == keyIMPLICIT_DEPENDS) {
271
0
        doing = doing_implicit_depends_lang;
272
0
      } else if (copy == keyCOMMENT) {
273
0
        doing = doing_comment;
274
0
        keywordExpectingValue = &keyCOMMENT;
275
0
      } else if (copy == keyDEPFILE) {
276
0
        doing = doing_depfile;
277
0
        if (!mf.GetGlobalGenerator()->SupportsCustomCommandDepfile()) {
278
0
          status.SetError(cmStrCat("Option DEPFILE not supported by ",
279
0
                                   mf.GetGlobalGenerator()->GetName()));
280
0
          return false;
281
0
        }
282
0
        keywordExpectingValue = &keyDEPFILE;
283
0
      } else if (copy == keyJOB_POOL) {
284
0
        doing = doing_job_pool;
285
0
        keywordExpectingValue = &keyJOB_POOL;
286
0
      } else if (copy == keyJOB_SERVER_AWARE) {
287
0
        doing = doing_job_server_aware;
288
0
        keywordExpectingValue = &keyJOB_SERVER_AWARE;
289
0
      }
290
0
    } else {
291
0
      keywordExpectingValue = nullptr; // Value is being processed now
292
0
      std::string filename;
293
0
      switch (doing) {
294
0
        case doing_output:
295
0
        case doing_outputs:
296
0
        case doing_byproducts:
297
0
          if (!cmSystemTools::FileIsFullPath(copy) &&
298
0
              cmGeneratorExpression::Find(copy) != 0) {
299
            // This is an output to be generated, so it should be
300
            // under the build tree.
301
0
            filename = cmStrCat(mf.GetCurrentBinaryDirectory(), '/');
302
0
          }
303
0
          filename += copy;
304
0
          cmSystemTools::ConvertToUnixSlashes(filename);
305
0
          break;
306
0
        case doing_source:
307
        // We do not want to convert the argument to SOURCE because
308
        // that option is only available for backward compatibility.
309
        // Old-style use of this command may use the SOURCE==TARGET
310
        // trick which we must preserve.  If we convert the source
311
        // to a full path then it will no longer equal the target.
312
0
        default:
313
0
          break;
314
0
      }
315
316
0
      if (cmSystemTools::FileIsFullPath(filename)) {
317
0
        filename = cmSystemTools::CollapseFullPath(filename);
318
0
      }
319
0
      switch (doing) {
320
0
        case doing_depfile:
321
0
          depfile = copy;
322
0
          break;
323
0
        case doing_job_pool:
324
0
          job_pool = copy;
325
0
          break;
326
0
        case doing_job_server_aware:
327
0
          job_server_aware = copy;
328
0
          break;
329
0
        case doing_working_directory:
330
0
          working = copy;
331
0
          break;
332
0
        case doing_source:
333
0
          source = copy;
334
0
          break;
335
0
        case doing_output:
336
0
          output.push_back(filename);
337
0
          break;
338
0
        case doing_main_dependency:
339
0
          main_dependency = copy;
340
0
          break;
341
0
        case doing_implicit_depends_lang:
342
0
          implicit_depends_lang = copy;
343
0
          doing = doing_implicit_depends_file;
344
0
          break;
345
0
        case doing_implicit_depends_file: {
346
          // An implicit dependency starting point is also an
347
          // explicit dependency.
348
0
          std::string dep = copy;
349
          // Upfront path conversion is correct because Genex
350
          // are not supported.
351
0
          cmSystemTools::ConvertToUnixSlashes(dep);
352
0
          depends.push_back(dep);
353
354
          // Add the implicit dependency language and file.
355
0
          implicit_depends.emplace_back(implicit_depends_lang, dep);
356
357
          // Switch back to looking for a language.
358
0
          doing = doing_implicit_depends_lang;
359
0
        } break;
360
0
        case doing_command:
361
0
          currentLine.push_back(copy);
362
0
          break;
363
0
        case doing_target:
364
0
          target = copy;
365
0
          break;
366
0
        case doing_depends:
367
0
          depends.push_back(copy);
368
0
          break;
369
0
        case doing_outputs:
370
0
          outputs.push_back(filename);
371
0
          break;
372
0
        case doing_byproducts:
373
0
          byproducts.push_back(filename);
374
0
          break;
375
0
        case doing_comment:
376
0
          if (!comment_buffer.empty()) {
377
0
            std::string const msg =
378
0
              "COMMENT requires exactly one argument, but multiple values "
379
0
              "or COMMENT keywords have been given.";
380
0
            if (cmp0175 == cmPolicies::NEW) {
381
0
              mf.IssueMessage(MessageType::FATAL_ERROR, msg);
382
0
              return false;
383
0
            }
384
0
            if (cmp0175 == cmPolicies::WARN) {
385
0
              mf.IssueDiagnostic(
386
0
                cmDiagnostics::CMD_AUTHOR,
387
0
                cmStrCat(msg, '\n',
388
0
                         cmPolicies::GetPolicyWarning(cmPolicies::CMP0175)));
389
0
            }
390
0
          }
391
0
          comment_buffer = copy;
392
0
          comment = comment_buffer.c_str();
393
0
          break;
394
0
        default:
395
0
          status.SetError("Wrong syntax. Unknown type of argument.");
396
0
          return false;
397
0
      }
398
0
    }
399
0
  }
400
401
  // Store the last command line finished.
402
0
  if (!currentLine.empty()) {
403
0
    commandLines.push_back(currentLine);
404
0
    currentLine.clear();
405
0
  }
406
407
  // At this point we could complain about the lack of arguments.  For
408
  // the moment, let's say that COMMAND, TARGET are always required.
409
0
  if (output.empty() && target.empty()) {
410
0
    status.SetError("Wrong syntax. A TARGET or OUTPUT must be specified.");
411
0
    return false;
412
0
  }
413
414
0
  if (source.empty() && !target.empty() && !output.empty()) {
415
0
    status.SetError(
416
0
      "Wrong syntax. A TARGET and OUTPUT can not both be specified.");
417
0
    return false;
418
0
  }
419
0
  if (append && output.empty()) {
420
0
    status.SetError("given APPEND option with no OUTPUT.");
421
0
    return false;
422
0
  }
423
0
  if (!implicit_depends.empty() && !depfile.empty() &&
424
0
      mf.GetGlobalGenerator()->GetName() != "Ninja") {
425
    // Makefiles generators does not support both at the same time
426
0
    status.SetError("IMPLICIT_DEPENDS and DEPFILE can not both be specified.");
427
0
    return false;
428
0
  }
429
430
0
  if (codegen) {
431
0
    if (output.empty()) {
432
0
      status.SetError("CODEGEN requires at least 1 OUTPUT.");
433
0
      return false;
434
0
    }
435
436
0
    if (append) {
437
0
      status.SetError("CODEGEN may not be used with APPEND.");
438
0
      return false;
439
0
    }
440
441
0
    if (!implicit_depends.empty()) {
442
0
      status.SetError("CODEGEN is not compatible with IMPLICIT_DEPENDS.");
443
0
      return false;
444
0
    }
445
446
0
    if (mf.GetPolicyStatus(cmPolicies::CMP0171) != cmPolicies::NEW) {
447
0
      status.SetError("CODEGEN option requires policy CMP0171 be set to NEW!");
448
0
      return false;
449
0
    }
450
0
  }
451
452
  // Check for an append request.
453
0
  if (append) {
454
0
    std::vector<std::string> unsupportedKeywordsUsed;
455
0
    std::set_difference(keywordsSeen.begin(), keywordsSeen.end(),
456
0
                        supportedAppendKeywords.begin(),
457
0
                        supportedAppendKeywords.end(),
458
0
                        std::back_inserter(unsupportedKeywordsUsed));
459
0
    if (!unsupportedKeywordsUsed.empty()) {
460
0
      std::string const msg =
461
0
        cmJoin(unsupportedKeywordsUsed, ", "_s,
462
0
               "The following keywords are not supported when using "
463
0
               "APPEND with add_custom_command(OUTPUT): "_s);
464
0
      if (cmp0175 == cmPolicies::NEW) {
465
0
        mf.IssueMessage(MessageType::FATAL_ERROR, msg);
466
0
        return false;
467
0
      }
468
0
      if (cmp0175 == cmPolicies::WARN) {
469
0
        mf.IssueDiagnostic(
470
0
          cmDiagnostics::CMD_AUTHOR,
471
0
          cmStrCat(msg, ".\n",
472
0
                   cmPolicies::GetPolicyWarning(cmPolicies::CMP0175)));
473
0
      }
474
0
    }
475
0
    mf.AppendCustomCommandToOutput(output[0], depends, implicit_depends,
476
0
                                   commandLines);
477
0
    return true;
478
0
  }
479
480
0
  if (uses_terminal && !job_pool.empty()) {
481
0
    status.SetError("JOB_POOL is shadowed by USES_TERMINAL.");
482
0
    return false;
483
0
  }
484
485
  // Choose which mode of the command to use.
486
0
  auto cc = cm::make_unique<cmCustomCommand>();
487
0
  cc->SetByproducts(byproducts);
488
0
  cc->SetCommandLines(commandLines);
489
0
  cc->SetComment(comment);
490
0
  cc->SetWorkingDirectory(working.c_str());
491
0
  cc->SetEscapeOldStyle(!verbatim);
492
0
  cc->SetUsesTerminal(uses_terminal);
493
0
  cc->SetDepfile(depfile);
494
0
  cc->SetJobPool(job_pool);
495
0
  cc->SetJobserverAware(cmIsOn(job_server_aware));
496
0
  cc->SetCommandExpandLists(command_expand_lists);
497
0
  cc->SetDependsExplicitOnly(depends_explicit_only);
498
0
  if (source.empty() && output.empty()) {
499
    // Source is empty, use the target.
500
0
    if (commandLines.empty()) {
501
0
      std::string const msg = "At least one COMMAND must be given.";
502
0
      if (cmp0175 == cmPolicies::NEW) {
503
0
        mf.IssueMessage(MessageType::FATAL_ERROR, msg);
504
0
        return false;
505
0
      }
506
0
      if (cmp0175 == cmPolicies::WARN) {
507
0
        mf.IssueDiagnostic(
508
0
          cmDiagnostics::CMD_AUTHOR,
509
0
          cmStrCat(msg, '\n',
510
0
                   cmPolicies::GetPolicyWarning(cmPolicies::CMP0175)));
511
0
      }
512
0
    }
513
514
0
    std::vector<std::string> unsupportedKeywordsUsed;
515
0
    std::set_difference(keywordsSeen.begin(), keywordsSeen.end(),
516
0
                        supportedTargetKeywords.begin(),
517
0
                        supportedTargetKeywords.end(),
518
0
                        std::back_inserter(unsupportedKeywordsUsed));
519
0
    if (!unsupportedKeywordsUsed.empty()) {
520
0
      std::string const msg =
521
0
        cmJoin(unsupportedKeywordsUsed, ", "_s,
522
0
               "The following keywords are not supported when using "
523
0
               "add_custom_command(TARGET): "_s);
524
0
      if (cmp0175 == cmPolicies::NEW) {
525
0
        mf.IssueMessage(MessageType::FATAL_ERROR, msg);
526
0
        return false;
527
0
      }
528
0
      if (cmp0175 == cmPolicies::WARN) {
529
0
        mf.IssueDiagnostic(
530
0
          cmDiagnostics::CMD_AUTHOR,
531
0
          cmStrCat(msg, ".\n",
532
0
                   cmPolicies::GetPolicyWarning(cmPolicies::CMP0175)));
533
0
      }
534
0
    }
535
0
    auto const prePostCount = keywordsSeen.count(keyPRE_BUILD) +
536
0
      keywordsSeen.count(keyPRE_LINK) + keywordsSeen.count(keyPOST_BUILD);
537
0
    if (prePostCount != 1) {
538
0
      std::string msg =
539
0
        "Exactly one of PRE_BUILD, PRE_LINK, or POST_BUILD must be given.";
540
0
      if (cmp0175 == cmPolicies::NEW) {
541
0
        mf.IssueMessage(MessageType::FATAL_ERROR, msg);
542
0
        return false;
543
0
      }
544
0
      if (cmp0175 == cmPolicies::WARN) {
545
0
        msg += " Assuming ";
546
0
        switch (cctype) {
547
0
          case cmCustomCommandType::PRE_BUILD:
548
0
            msg += "PRE_BUILD";
549
0
            break;
550
0
          case cmCustomCommandType::PRE_LINK:
551
0
            msg += "PRE_LINK";
552
0
            break;
553
0
          case cmCustomCommandType::POST_BUILD:
554
0
            msg += "POST_BUILD";
555
0
        }
556
0
        mf.IssueDiagnostic(
557
0
          cmDiagnostics::CMD_AUTHOR,
558
0
          cmStrCat(msg, " to preserve backward compatibility.\n",
559
0
                   cmPolicies::GetPolicyWarning(cmPolicies::CMP0175)));
560
0
      }
561
0
    }
562
0
    mf.AddCustomCommandToTarget(target, cctype, std::move(cc));
563
0
  } else if (target.empty()) {
564
    // Target is empty, use the output.
565
0
    std::vector<std::string> unsupportedKeywordsUsed;
566
0
    std::set_difference(keywordsSeen.begin(), keywordsSeen.end(),
567
0
                        supportedOutputKeywords.begin(),
568
0
                        supportedOutputKeywords.end(),
569
0
                        std::back_inserter(unsupportedKeywordsUsed));
570
0
    if (!unsupportedKeywordsUsed.empty()) {
571
0
      std::string const msg =
572
0
        cmJoin(unsupportedKeywordsUsed, ", "_s,
573
0
               "The following keywords are not supported when using "
574
0
               "add_custom_command(OUTPUT): "_s);
575
0
      if (cmp0175 == cmPolicies::NEW) {
576
0
        mf.IssueMessage(MessageType::FATAL_ERROR, msg);
577
0
        return false;
578
0
      }
579
0
      if (cmp0175 == cmPolicies::WARN) {
580
0
        mf.IssueDiagnostic(
581
0
          cmDiagnostics::CMD_AUTHOR,
582
0
          cmStrCat(msg, ".\n",
583
0
                   cmPolicies::GetPolicyWarning(cmPolicies::CMP0175)));
584
0
      }
585
0
    }
586
0
    cc->SetOutputs(output);
587
0
    cc->SetMainDependency(main_dependency);
588
0
    cc->SetDepends(depends);
589
0
    cc->SetCodegen(codegen);
590
0
    cc->SetImplicitDepends(implicit_depends);
591
0
    mf.AddCustomCommandToOutput(std::move(cc));
592
0
  } else {
593
0
    mf.IssueMessage(
594
0
      MessageType::FATAL_ERROR,
595
0
      "The SOURCE signatures of add_custom_command are no longer supported.");
596
0
    return false;
597
0
  }
598
599
0
  return true;
600
0
}