You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.9 KiB

  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmGetDirectoryPropertyCommand.h"
  14. #include "cmake.h"
  15. // cmGetDirectoryPropertyCommand
  16. bool cmGetDirectoryPropertyCommand::InitialPass(
  17. std::vector<std::string> const& args)
  18. {
  19. if(args.size() < 2 )
  20. {
  21. this->SetError("called with incorrect number of arguments");
  22. return false;
  23. }
  24. std::vector<std::string>::const_iterator i = args.begin();
  25. std::string variable = *i;
  26. ++i;
  27. std::string output = "";
  28. // get the directory argument if there is one
  29. cmMakefile *dir = this->Makefile;
  30. if (*i == "DIRECTORY")
  31. {
  32. ++i;
  33. if (i == args.end())
  34. {
  35. this->SetError
  36. ("DIRECTORY argument provided without subsequent arguments");
  37. return false;
  38. }
  39. std::string sd = *i;
  40. // make sure the start dir is a full path
  41. if (!cmSystemTools::FileIsFullPath(sd.c_str()))
  42. {
  43. sd = this->Makefile->GetStartDirectory();
  44. sd += "/";
  45. sd += *i;
  46. }
  47. // The local generators are associated with collapsed paths.
  48. sd = cmSystemTools::CollapseFullPath(sd.c_str());
  49. // lookup the makefile from the directory name
  50. cmLocalGenerator *lg =
  51. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  52. FindLocalGenerator(sd.c_str());
  53. if (!lg)
  54. {
  55. this->SetError
  56. ("DIRECTORY argument provided but requested directory not found. "
  57. "This could be because the directory argument was invalid or, "
  58. "it is valid but has not been processed yet.");
  59. return false;
  60. }
  61. dir = lg->GetMakefile();
  62. ++i;
  63. }
  64. // OK, now we have the directory to process, we just get the requested
  65. // information out of it
  66. if ( *i == "DEFINITION" )
  67. {
  68. ++i;
  69. if (i == args.end())
  70. {
  71. this->SetError("A request for a variable definition was made without "
  72. "providing the name of the variable to get.");
  73. return false;
  74. }
  75. output = dir->GetSafeDefinition(i->c_str());
  76. this->Makefile->AddDefinition(variable.c_str(), output.c_str());
  77. return true;
  78. }
  79. const char *prop = dir->GetProperty(i->c_str());
  80. if (prop)
  81. {
  82. this->Makefile->AddDefinition(variable.c_str(), prop);
  83. return true;
  84. }
  85. this->Makefile->AddDefinition(variable.c_str(), "");
  86. return true;
  87. }