cmGetDirectoryPropertyCommand.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmGetDirectoryPropertyCommand.h"
  11. #include "cmake.h"
  12. // cmGetDirectoryPropertyCommand
  13. bool cmGetDirectoryPropertyCommand
  14. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  15. {
  16. if(args.size() < 2 )
  17. {
  18. this->SetError("called with incorrect number of arguments");
  19. return false;
  20. }
  21. std::vector<std::string>::const_iterator i = args.begin();
  22. std::string variable = *i;
  23. ++i;
  24. // get the directory argument if there is one
  25. cmMakefile *dir = this->Makefile;
  26. if (*i == "DIRECTORY")
  27. {
  28. ++i;
  29. if (i == args.end())
  30. {
  31. this->SetError
  32. ("DIRECTORY argument provided without subsequent arguments");
  33. return false;
  34. }
  35. std::string sd = *i;
  36. // make sure the start dir is a full path
  37. if (!cmSystemTools::FileIsFullPath(sd.c_str()))
  38. {
  39. sd = this->Makefile->GetCurrentSourceDirectory();
  40. sd += "/";
  41. sd += *i;
  42. }
  43. // The local generators are associated with collapsed paths.
  44. sd = cmSystemTools::CollapseFullPath(sd);
  45. // lookup the makefile from the directory name
  46. cmLocalGenerator *lg =
  47. this->Makefile->GetGlobalGenerator()->
  48. FindLocalGenerator(sd);
  49. if (!lg)
  50. {
  51. this->SetError
  52. ("DIRECTORY argument provided but requested directory not found. "
  53. "This could be because the directory argument was invalid or, "
  54. "it is valid but has not been processed yet.");
  55. return false;
  56. }
  57. dir = lg->GetMakefile();
  58. ++i;
  59. }
  60. // OK, now we have the directory to process, we just get the requested
  61. // information out of it
  62. if ( *i == "DEFINITION" )
  63. {
  64. ++i;
  65. if (i == args.end())
  66. {
  67. this->SetError("A request for a variable definition was made without "
  68. "providing the name of the variable to get.");
  69. return false;
  70. }
  71. std::string output = dir->GetSafeDefinition(*i);
  72. this->Makefile->AddDefinition(variable, output.c_str());
  73. return true;
  74. }
  75. const char *prop = 0;
  76. if (!i->empty())
  77. {
  78. if (*i == "DEFINITIONS")
  79. {
  80. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0059))
  81. {
  82. case cmPolicies::WARN:
  83. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
  84. cmPolicies::GetPolicyWarning(cmPolicies::CMP0059));
  85. case cmPolicies::OLD:
  86. this->StoreResult(variable,
  87. this->Makefile->GetDefineFlagsCMP0059());
  88. return true;
  89. case cmPolicies::NEW:
  90. case cmPolicies::REQUIRED_ALWAYS:
  91. case cmPolicies::REQUIRED_IF_USED:
  92. break;
  93. }
  94. }
  95. prop = dir->GetProperty(*i);
  96. }
  97. this->StoreResult(variable, prop);
  98. return true;
  99. }
  100. void cmGetDirectoryPropertyCommand::StoreResult(std::string const& variable,
  101. const char* prop)
  102. {
  103. if (prop)
  104. {
  105. this->Makefile->AddDefinition(variable, prop);
  106. return;
  107. }
  108. this->Makefile->AddDefinition(variable, "");
  109. }