cmGetDirectoryPropertyCommand.cxx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. prop = dir->GetProperty(*i);
  79. }
  80. this->StoreResult(variable, prop);
  81. return true;
  82. }
  83. void cmGetDirectoryPropertyCommand::StoreResult(std::string const& variable,
  84. const char* prop)
  85. {
  86. if (prop)
  87. {
  88. this->Makefile->AddDefinition(variable, prop);
  89. return;
  90. }
  91. this->Makefile->AddDefinition(variable, "");
  92. }