cmGetDirectoryPropertyCommand.cxx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. std::string output = "";
  25. // get the directory argument if there is one
  26. cmMakefile *dir = this->Makefile;
  27. if (*i == "DIRECTORY")
  28. {
  29. ++i;
  30. if (i == args.end())
  31. {
  32. this->SetError
  33. ("DIRECTORY argument provided without subsequent arguments");
  34. return false;
  35. }
  36. std::string sd = *i;
  37. // make sure the start dir is a full path
  38. if (!cmSystemTools::FileIsFullPath(sd.c_str()))
  39. {
  40. sd = this->Makefile->GetCurrentSourceDirectory();
  41. sd += "/";
  42. sd += *i;
  43. }
  44. // The local generators are associated with collapsed paths.
  45. sd = cmSystemTools::CollapseFullPath(sd);
  46. // lookup the makefile from the directory name
  47. cmLocalGenerator *lg =
  48. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  49. FindLocalGenerator(sd);
  50. if (!lg)
  51. {
  52. this->SetError
  53. ("DIRECTORY argument provided but requested directory not found. "
  54. "This could be because the directory argument was invalid or, "
  55. "it is valid but has not been processed yet.");
  56. return false;
  57. }
  58. dir = lg->GetMakefile();
  59. ++i;
  60. }
  61. // OK, now we have the directory to process, we just get the requested
  62. // information out of it
  63. if ( *i == "DEFINITION" )
  64. {
  65. ++i;
  66. if (i == args.end())
  67. {
  68. this->SetError("A request for a variable definition was made without "
  69. "providing the name of the variable to get.");
  70. return false;
  71. }
  72. output = dir->GetSafeDefinition(*i);
  73. this->Makefile->AddDefinition(variable, output.c_str());
  74. return true;
  75. }
  76. const char *prop = dir->GetProperty(*i);
  77. if (prop)
  78. {
  79. this->Makefile->AddDefinition(variable, prop);
  80. return true;
  81. }
  82. this->Makefile->AddDefinition(variable, "");
  83. return true;
  84. }