cmGetDirectoryPropertyCommand.cxx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 "cmGetDirectoryPropertyCommand.h"
  4. #include "cmGlobalGenerator.h"
  5. #include "cmMakefile.h"
  6. #include "cmPolicies.h"
  7. #include "cmSystemTools.h"
  8. #include "cmake.h"
  9. class cmExecutionStatus;
  10. // cmGetDirectoryPropertyCommand
  11. bool cmGetDirectoryPropertyCommand::InitialPass(
  12. std::vector<std::string> const& args, cmExecutionStatus&)
  13. {
  14. if (args.size() < 2) {
  15. this->SetError("called with incorrect number of arguments");
  16. return false;
  17. }
  18. std::vector<std::string>::const_iterator i = args.begin();
  19. std::string const& variable = *i;
  20. ++i;
  21. // get the directory argument if there is one
  22. cmMakefile* dir = this->Makefile;
  23. if (*i == "DIRECTORY") {
  24. ++i;
  25. if (i == args.end()) {
  26. this->SetError(
  27. "DIRECTORY argument provided without subsequent arguments");
  28. return false;
  29. }
  30. std::string sd = *i;
  31. // make sure the start dir is a full path
  32. if (!cmSystemTools::FileIsFullPath(sd)) {
  33. sd = this->Makefile->GetCurrentSourceDirectory();
  34. sd += "/";
  35. sd += *i;
  36. }
  37. // The local generators are associated with collapsed paths.
  38. sd = cmSystemTools::CollapseFullPath(sd);
  39. // lookup the makefile from the directory name
  40. dir = this->Makefile->GetGlobalGenerator()->FindMakefile(sd);
  41. if (!dir) {
  42. this->SetError(
  43. "DIRECTORY argument provided but requested directory not found. "
  44. "This could be because the directory argument was invalid or, "
  45. "it is valid but has not been processed yet.");
  46. return false;
  47. }
  48. ++i;
  49. }
  50. // OK, now we have the directory to process, we just get the requested
  51. // information out of it
  52. if (*i == "DEFINITION") {
  53. ++i;
  54. if (i == args.end()) {
  55. this->SetError("A request for a variable definition was made without "
  56. "providing the name of the variable to get.");
  57. return false;
  58. }
  59. std::string output = dir->GetSafeDefinition(*i);
  60. this->Makefile->AddDefinition(variable, output.c_str());
  61. return true;
  62. }
  63. const char* prop = nullptr;
  64. if (!i->empty()) {
  65. if (*i == "DEFINITIONS") {
  66. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0059)) {
  67. case cmPolicies::WARN:
  68. this->Makefile->IssueMessage(
  69. cmake::AUTHOR_WARNING,
  70. cmPolicies::GetPolicyWarning(cmPolicies::CMP0059));
  71. CM_FALLTHROUGH;
  72. case cmPolicies::OLD:
  73. this->StoreResult(variable, this->Makefile->GetDefineFlagsCMP0059());
  74. return true;
  75. case cmPolicies::NEW:
  76. case cmPolicies::REQUIRED_ALWAYS:
  77. case cmPolicies::REQUIRED_IF_USED:
  78. break;
  79. }
  80. }
  81. prop = dir->GetProperty(*i);
  82. }
  83. this->StoreResult(variable, prop);
  84. return true;
  85. }
  86. void cmGetDirectoryPropertyCommand::StoreResult(std::string const& variable,
  87. const char* prop)
  88. {
  89. if (prop) {
  90. this->Makefile->AddDefinition(variable, prop);
  91. return;
  92. }
  93. this->Makefile->AddDefinition(variable, "");
  94. }