cmAddCustomCommandCommand.cxx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  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. keyUSES_TERMINAL,
  148. keyVERBATIM,
  149. keyWORKING_DIRECTORY
  150. };
  151. /* clang-format on */
  152. static std::set<std::string> const supportedOutputKeywords{
  153. keyAPPEND,
  154. keyARGS,
  155. keyBYPRODUCTS,
  156. keyCODEGEN,
  157. keyCOMMAND,
  158. keyCOMMAND_EXPAND_LISTS,
  159. keyCOMMENT,
  160. keyDEPENDS,
  161. keyDEPENDS_EXPLICIT_ONLY,
  162. keyDEPFILE,
  163. keyIMPLICIT_DEPENDS,
  164. keyJOB_POOL,
  165. keyJOB_SERVER_AWARE,
  166. keyMAIN_DEPENDENCY,
  167. keyOUTPUT,
  168. keyUSES_TERMINAL,
  169. keyVERBATIM,
  170. keyWORKING_DIRECTORY
  171. };
  172. /* clang-format off */
  173. static std::set<std::string> const supportedAppendKeywords{
  174. keyAPPEND,
  175. keyARGS,
  176. keyCOMMAND,
  177. keyCOMMENT, // Allowed but ignored
  178. keyDEPENDS,
  179. keyIMPLICIT_DEPENDS,
  180. keyMAIN_DEPENDENCY, // Allowed but ignored
  181. keyOUTPUT,
  182. keyWORKING_DIRECTORY // Allowed but ignored
  183. };
  184. /* clang-format on */
  185. std::set<std::string> keywordsSeen;
  186. std::string const* keywordExpectingValue = nullptr;
  187. auto const cmp0175 = mf.GetPolicyStatus(cmPolicies::CMP0175);
  188. for (std::string const& copy : args) {
  189. if (keywords.count(copy)) {
  190. // Check if a preceding keyword expected a value but there wasn't one
  191. if (keywordExpectingValue) {
  192. std::string const msg =
  193. cmStrCat("Keyword ", *keywordExpectingValue,
  194. " requires a value, but none was given.");
  195. if (cmp0175 == cmPolicies::NEW) {
  196. mf.IssueMessage(MessageType::FATAL_ERROR, msg);
  197. return false;
  198. }
  199. if (cmp0175 == cmPolicies::WARN) {
  200. mf.IssueMessage(
  201. MessageType::AUTHOR_WARNING,
  202. cmStrCat(msg, '\n',
  203. cmPolicies::GetPolicyWarning(cmPolicies::CMP0175)));
  204. }
  205. }
  206. keywordExpectingValue = nullptr;
  207. keywordsSeen.insert(copy);
  208. if (copy == keySOURCE) {
  209. doing = doing_source;
  210. keywordExpectingValue = &keySOURCE;
  211. } else if (copy == keyCOMMAND) {
  212. doing = doing_command;
  213. // Save the current command before starting the next command.
  214. if (!currentLine.empty()) {
  215. commandLines.push_back(currentLine);
  216. currentLine.clear();
  217. }
  218. } else if (copy == keyPRE_BUILD) {
  219. cctype = cmCustomCommandType::PRE_BUILD;
  220. } else if (copy == keyPRE_LINK) {
  221. cctype = cmCustomCommandType::PRE_LINK;
  222. } else if (copy == keyPOST_BUILD) {
  223. cctype = cmCustomCommandType::POST_BUILD;
  224. } else if (copy == keyVERBATIM) {
  225. verbatim = true;
  226. } else if (copy == keyAPPEND) {
  227. append = true;
  228. } else if (copy == keyUSES_TERMINAL) {
  229. uses_terminal = true;
  230. } else if (copy == keyCOMMAND_EXPAND_LISTS) {
  231. command_expand_lists = true;
  232. } else if (copy == keyDEPENDS_EXPLICIT_ONLY) {
  233. depends_explicit_only = true;
  234. } else if (copy == keyCODEGEN) {
  235. codegen = true;
  236. } else if (copy == keyTARGET) {
  237. doing = doing_target;
  238. keywordExpectingValue = &keyTARGET;
  239. } else if (copy == keyARGS) {
  240. // Ignore this old keyword.
  241. } else if (copy == keyDEPENDS) {
  242. doing = doing_depends;
  243. } else if (copy == keyOUTPUTS) {
  244. doing = doing_outputs;
  245. } else if (copy == keyOUTPUT) {
  246. doing = doing_output;
  247. keywordExpectingValue = &keyOUTPUT;
  248. } else if (copy == keyBYPRODUCTS) {
  249. doing = doing_byproducts;
  250. } else if (copy == keyWORKING_DIRECTORY) {
  251. doing = doing_working_directory;
  252. keywordExpectingValue = &keyWORKING_DIRECTORY;
  253. } else if (copy == keyMAIN_DEPENDENCY) {
  254. doing = doing_main_dependency;
  255. keywordExpectingValue = &keyMAIN_DEPENDENCY;
  256. } else if (copy == keyIMPLICIT_DEPENDS) {
  257. doing = doing_implicit_depends_lang;
  258. } else if (copy == keyCOMMENT) {
  259. doing = doing_comment;
  260. keywordExpectingValue = &keyCOMMENT;
  261. } else if (copy == keyDEPFILE) {
  262. doing = doing_depfile;
  263. if (!mf.GetGlobalGenerator()->SupportsCustomCommandDepfile()) {
  264. status.SetError(cmStrCat("Option DEPFILE not supported by ",
  265. mf.GetGlobalGenerator()->GetName()));
  266. return false;
  267. }
  268. keywordExpectingValue = &keyDEPFILE;
  269. } else if (copy == keyJOB_POOL) {
  270. doing = doing_job_pool;
  271. keywordExpectingValue = &keyJOB_POOL;
  272. } else if (copy == keyJOB_SERVER_AWARE) {
  273. doing = doing_job_server_aware;
  274. keywordExpectingValue = &keyJOB_SERVER_AWARE;
  275. }
  276. } else {
  277. keywordExpectingValue = nullptr; // Value is being processed now
  278. std::string filename;
  279. switch (doing) {
  280. case doing_output:
  281. case doing_outputs:
  282. case doing_byproducts:
  283. if (!cmSystemTools::FileIsFullPath(copy) &&
  284. cmGeneratorExpression::Find(copy) != 0) {
  285. // This is an output to be generated, so it should be
  286. // under the build tree.
  287. filename = cmStrCat(mf.GetCurrentBinaryDirectory(), '/');
  288. }
  289. filename += copy;
  290. cmSystemTools::ConvertToUnixSlashes(filename);
  291. break;
  292. case doing_source:
  293. // We do not want to convert the argument to SOURCE because
  294. // that option is only available for backward compatibility.
  295. // Old-style use of this command may use the SOURCE==TARGET
  296. // trick which we must preserve. If we convert the source
  297. // to a full path then it will no longer equal the target.
  298. default:
  299. break;
  300. }
  301. if (cmSystemTools::FileIsFullPath(filename)) {
  302. filename = cmSystemTools::CollapseFullPath(filename);
  303. }
  304. switch (doing) {
  305. case doing_depfile:
  306. depfile = copy;
  307. break;
  308. case doing_job_pool:
  309. job_pool = copy;
  310. break;
  311. case doing_job_server_aware:
  312. job_server_aware = copy;
  313. break;
  314. case doing_working_directory:
  315. working = copy;
  316. break;
  317. case doing_source:
  318. source = copy;
  319. break;
  320. case doing_output:
  321. output.push_back(filename);
  322. break;
  323. case doing_main_dependency:
  324. main_dependency = copy;
  325. break;
  326. case doing_implicit_depends_lang:
  327. implicit_depends_lang = copy;
  328. doing = doing_implicit_depends_file;
  329. break;
  330. case doing_implicit_depends_file: {
  331. // An implicit dependency starting point is also an
  332. // explicit dependency.
  333. std::string dep = copy;
  334. // Upfront path conversion is correct because Genex
  335. // are not supported.
  336. cmSystemTools::ConvertToUnixSlashes(dep);
  337. depends.push_back(dep);
  338. // Add the implicit dependency language and file.
  339. implicit_depends.emplace_back(implicit_depends_lang, dep);
  340. // Switch back to looking for a language.
  341. doing = doing_implicit_depends_lang;
  342. } break;
  343. case doing_command:
  344. currentLine.push_back(copy);
  345. break;
  346. case doing_target:
  347. target = copy;
  348. break;
  349. case doing_depends:
  350. depends.push_back(copy);
  351. break;
  352. case doing_outputs:
  353. outputs.push_back(filename);
  354. break;
  355. case doing_byproducts:
  356. byproducts.push_back(filename);
  357. break;
  358. case doing_comment:
  359. if (!comment_buffer.empty()) {
  360. std::string const msg =
  361. "COMMENT requires exactly one argument, but multiple values "
  362. "or COMMENT keywords have been given.";
  363. if (cmp0175 == cmPolicies::NEW) {
  364. mf.IssueMessage(MessageType::FATAL_ERROR, msg);
  365. return false;
  366. }
  367. if (cmp0175 == cmPolicies::WARN) {
  368. mf.IssueMessage(
  369. MessageType::AUTHOR_WARNING,
  370. cmStrCat(msg, '\n',
  371. cmPolicies::GetPolicyWarning(cmPolicies::CMP0175)));
  372. }
  373. }
  374. comment_buffer = copy;
  375. comment = comment_buffer.c_str();
  376. break;
  377. default:
  378. status.SetError("Wrong syntax. Unknown type of argument.");
  379. return false;
  380. }
  381. }
  382. }
  383. // Store the last command line finished.
  384. if (!currentLine.empty()) {
  385. commandLines.push_back(currentLine);
  386. currentLine.clear();
  387. }
  388. // At this point we could complain about the lack of arguments. For
  389. // the moment, let's say that COMMAND, TARGET are always required.
  390. if (output.empty() && target.empty()) {
  391. status.SetError("Wrong syntax. A TARGET or OUTPUT must be specified.");
  392. return false;
  393. }
  394. if (source.empty() && !target.empty() && !output.empty()) {
  395. status.SetError(
  396. "Wrong syntax. A TARGET and OUTPUT can not both be specified.");
  397. return false;
  398. }
  399. if (append && output.empty()) {
  400. status.SetError("given APPEND option with no OUTPUT.");
  401. return false;
  402. }
  403. if (!implicit_depends.empty() && !depfile.empty() &&
  404. mf.GetGlobalGenerator()->GetName() != "Ninja") {
  405. // Makefiles generators does not support both at the same time
  406. status.SetError("IMPLICIT_DEPENDS and DEPFILE can not both be specified.");
  407. return false;
  408. }
  409. if (codegen) {
  410. if (output.empty()) {
  411. status.SetError("CODEGEN requires at least 1 OUTPUT.");
  412. return false;
  413. }
  414. if (append) {
  415. status.SetError("CODEGEN may not be used with APPEND.");
  416. return false;
  417. }
  418. if (!implicit_depends.empty()) {
  419. status.SetError("CODEGEN is not compatible with IMPLICIT_DEPENDS.");
  420. return false;
  421. }
  422. if (mf.GetPolicyStatus(cmPolicies::CMP0171) != cmPolicies::NEW) {
  423. status.SetError("CODEGEN option requires policy CMP0171 be set to NEW!");
  424. return false;
  425. }
  426. }
  427. // Check for an append request.
  428. if (append) {
  429. std::vector<std::string> unsupportedKeywordsUsed;
  430. std::set_difference(keywordsSeen.begin(), keywordsSeen.end(),
  431. supportedAppendKeywords.begin(),
  432. supportedAppendKeywords.end(),
  433. std::back_inserter(unsupportedKeywordsUsed));
  434. if (!unsupportedKeywordsUsed.empty()) {
  435. std::string const msg =
  436. cmJoin(unsupportedKeywordsUsed, ", "_s,
  437. "The following keywords are not supported when using "
  438. "APPEND with add_custom_command(OUTPUT): "_s);
  439. if (cmp0175 == cmPolicies::NEW) {
  440. mf.IssueMessage(MessageType::FATAL_ERROR, msg);
  441. return false;
  442. }
  443. if (cmp0175 == cmPolicies::WARN) {
  444. mf.IssueMessage(
  445. MessageType::AUTHOR_WARNING,
  446. cmStrCat(msg, ".\n",
  447. cmPolicies::GetPolicyWarning(cmPolicies::CMP0175)));
  448. }
  449. }
  450. mf.AppendCustomCommandToOutput(output[0], depends, implicit_depends,
  451. commandLines);
  452. return true;
  453. }
  454. if (uses_terminal && !job_pool.empty()) {
  455. status.SetError("JOB_POOL is shadowed by USES_TERMINAL.");
  456. return false;
  457. }
  458. // Choose which mode of the command to use.
  459. auto cc = cm::make_unique<cmCustomCommand>();
  460. cc->SetByproducts(byproducts);
  461. cc->SetCommandLines(commandLines);
  462. cc->SetComment(comment);
  463. cc->SetWorkingDirectory(working.c_str());
  464. cc->SetEscapeOldStyle(!verbatim);
  465. cc->SetUsesTerminal(uses_terminal);
  466. cc->SetDepfile(depfile);
  467. cc->SetJobPool(job_pool);
  468. cc->SetJobserverAware(cmIsOn(job_server_aware));
  469. cc->SetCommandExpandLists(command_expand_lists);
  470. cc->SetDependsExplicitOnly(depends_explicit_only);
  471. if (source.empty() && output.empty()) {
  472. // Source is empty, use the target.
  473. if (commandLines.empty()) {
  474. std::string const msg = "At least one COMMAND must be given.";
  475. if (cmp0175 == cmPolicies::NEW) {
  476. mf.IssueMessage(MessageType::FATAL_ERROR, msg);
  477. return false;
  478. }
  479. if (cmp0175 == cmPolicies::WARN) {
  480. mf.IssueMessage(
  481. MessageType::AUTHOR_WARNING,
  482. cmStrCat(msg, '\n',
  483. cmPolicies::GetPolicyWarning(cmPolicies::CMP0175)));
  484. }
  485. }
  486. std::vector<std::string> unsupportedKeywordsUsed;
  487. std::set_difference(keywordsSeen.begin(), keywordsSeen.end(),
  488. supportedTargetKeywords.begin(),
  489. supportedTargetKeywords.end(),
  490. std::back_inserter(unsupportedKeywordsUsed));
  491. if (!unsupportedKeywordsUsed.empty()) {
  492. std::string const msg =
  493. cmJoin(unsupportedKeywordsUsed, ", "_s,
  494. "The following keywords are not supported when using "
  495. "add_custom_command(TARGET): "_s);
  496. if (cmp0175 == cmPolicies::NEW) {
  497. mf.IssueMessage(MessageType::FATAL_ERROR, msg);
  498. return false;
  499. }
  500. if (cmp0175 == cmPolicies::WARN) {
  501. mf.IssueMessage(
  502. MessageType::AUTHOR_WARNING,
  503. cmStrCat(msg, ".\n",
  504. cmPolicies::GetPolicyWarning(cmPolicies::CMP0175)));
  505. }
  506. }
  507. auto const prePostCount = keywordsSeen.count(keyPRE_BUILD) +
  508. keywordsSeen.count(keyPRE_LINK) + keywordsSeen.count(keyPOST_BUILD);
  509. if (prePostCount != 1) {
  510. std::string msg =
  511. "Exactly one of PRE_BUILD, PRE_LINK, or POST_BUILD must be given.";
  512. if (cmp0175 == cmPolicies::NEW) {
  513. mf.IssueMessage(MessageType::FATAL_ERROR, msg);
  514. return false;
  515. }
  516. if (cmp0175 == cmPolicies::WARN) {
  517. msg += " Assuming ";
  518. switch (cctype) {
  519. case cmCustomCommandType::PRE_BUILD:
  520. msg += "PRE_BUILD";
  521. break;
  522. case cmCustomCommandType::PRE_LINK:
  523. msg += "PRE_LINK";
  524. break;
  525. case cmCustomCommandType::POST_BUILD:
  526. msg += "POST_BUILD";
  527. }
  528. mf.IssueMessage(
  529. MessageType::AUTHOR_WARNING,
  530. cmStrCat(msg, " to preserve backward compatibility.\n",
  531. cmPolicies::GetPolicyWarning(cmPolicies::CMP0175)));
  532. }
  533. }
  534. mf.AddCustomCommandToTarget(target, cctype, std::move(cc));
  535. } else if (target.empty()) {
  536. // Target is empty, use the output.
  537. std::vector<std::string> unsupportedKeywordsUsed;
  538. std::set_difference(keywordsSeen.begin(), keywordsSeen.end(),
  539. supportedOutputKeywords.begin(),
  540. supportedOutputKeywords.end(),
  541. std::back_inserter(unsupportedKeywordsUsed));
  542. if (!unsupportedKeywordsUsed.empty()) {
  543. std::string const msg =
  544. cmJoin(unsupportedKeywordsUsed, ", "_s,
  545. "The following keywords are not supported when using "
  546. "add_custom_command(OUTPUT): "_s);
  547. if (cmp0175 == cmPolicies::NEW) {
  548. mf.IssueMessage(MessageType::FATAL_ERROR, msg);
  549. return false;
  550. }
  551. if (cmp0175 == cmPolicies::WARN) {
  552. mf.IssueMessage(
  553. MessageType::AUTHOR_WARNING,
  554. cmStrCat(msg, ".\n",
  555. cmPolicies::GetPolicyWarning(cmPolicies::CMP0175)));
  556. }
  557. }
  558. cc->SetOutputs(output);
  559. cc->SetMainDependency(main_dependency);
  560. cc->SetDepends(depends);
  561. cc->SetCodegen(codegen);
  562. cc->SetImplicitDepends(implicit_depends);
  563. mf.AddCustomCommandToOutput(std::move(cc));
  564. } else {
  565. if (!byproducts.empty()) {
  566. status.SetError(
  567. "BYPRODUCTS may not be specified with SOURCE signatures");
  568. return false;
  569. }
  570. if (uses_terminal) {
  571. status.SetError("USES_TERMINAL may not be used with SOURCE signatures");
  572. return false;
  573. }
  574. bool issueMessage = true;
  575. std::ostringstream e;
  576. MessageType messageType = MessageType::AUTHOR_WARNING;
  577. switch (mf.GetPolicyStatus(cmPolicies::CMP0050)) {
  578. case cmPolicies::WARN:
  579. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0050) << "\n";
  580. break;
  581. case cmPolicies::OLD:
  582. issueMessage = false;
  583. break;
  584. case cmPolicies::NEW:
  585. messageType = MessageType::FATAL_ERROR;
  586. break;
  587. }
  588. if (issueMessage) {
  589. e << "The SOURCE signatures of add_custom_command are no longer "
  590. "supported.";
  591. mf.IssueMessage(messageType, e.str());
  592. if (messageType == MessageType::FATAL_ERROR) {
  593. return false;
  594. }
  595. }
  596. // Use the old-style mode for backward compatibility.
  597. mf.AddCustomCommandOldStyle(target, outputs, depends, source, commandLines,
  598. comment);
  599. }
  600. return true;
  601. }