cmMessageCommand.cxx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 "cmMessageCommand.h"
  4. #include "cmAlgorithms.h"
  5. #include "cmMakefile.h"
  6. #include "cmMessageType.h"
  7. #include "cmMessenger.h"
  8. #include "cmRange.h"
  9. #include "cmSystemTools.h"
  10. class cmExecutionStatus;
  11. // cmLibraryCommand
  12. bool cmMessageCommand::InitialPass(std::vector<std::string> const& args,
  13. cmExecutionStatus&)
  14. {
  15. if (args.empty()) {
  16. this->SetError("called with incorrect number of arguments");
  17. return false;
  18. }
  19. std::vector<std::string>::const_iterator i = args.begin();
  20. MessageType type = MessageType::MESSAGE;
  21. bool status = false;
  22. bool fatal = false;
  23. if (*i == "SEND_ERROR") {
  24. type = MessageType::FATAL_ERROR;
  25. ++i;
  26. } else if (*i == "FATAL_ERROR") {
  27. fatal = true;
  28. type = MessageType::FATAL_ERROR;
  29. ++i;
  30. } else if (*i == "WARNING") {
  31. type = MessageType::WARNING;
  32. ++i;
  33. } else if (*i == "AUTHOR_WARNING") {
  34. if (this->Makefile->IsSet("CMAKE_SUPPRESS_DEVELOPER_ERRORS") &&
  35. !this->Makefile->IsOn("CMAKE_SUPPRESS_DEVELOPER_ERRORS")) {
  36. fatal = true;
  37. type = MessageType::AUTHOR_ERROR;
  38. } else if (!this->Makefile->IsOn("CMAKE_SUPPRESS_DEVELOPER_WARNINGS")) {
  39. type = MessageType::AUTHOR_WARNING;
  40. } else {
  41. return true;
  42. }
  43. ++i;
  44. } else if (*i == "STATUS") {
  45. status = true;
  46. ++i;
  47. } else if (*i == "DEPRECATION") {
  48. if (this->Makefile->IsOn("CMAKE_ERROR_DEPRECATED")) {
  49. fatal = true;
  50. type = MessageType::DEPRECATION_ERROR;
  51. } else if ((!this->Makefile->IsSet("CMAKE_WARN_DEPRECATED") ||
  52. this->Makefile->IsOn("CMAKE_WARN_DEPRECATED"))) {
  53. type = MessageType::DEPRECATION_WARNING;
  54. } else {
  55. return true;
  56. }
  57. ++i;
  58. }
  59. std::string message = cmJoin(cmMakeRange(i, args.end()), std::string());
  60. if (type != MessageType::MESSAGE) {
  61. // we've overridden the message type, above, so display it directly
  62. cmMessenger* m = this->Makefile->GetMessenger();
  63. m->DisplayMessage(type, message, this->Makefile->GetBacktrace());
  64. } else {
  65. if (status) {
  66. this->Makefile->DisplayStatus(message, -1);
  67. } else {
  68. cmSystemTools::Message(message);
  69. }
  70. }
  71. if (fatal) {
  72. cmSystemTools::SetFatalErrorOccured();
  73. }
  74. return true;
  75. }