cmMessageCommand.cxx 2.3 KB

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