cmMessageCommand.cxx 2.2 KB

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