1
0

cmAddCustomCommandCommand.cxx 20 KB

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