cmGetDirectoryPropertyCommand.cxx 3.0 KB

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