cmGetDirectoryPropertyCommand.cxx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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>::size_type cc;
  25. std::vector<std::string>::const_iterator i = args.begin();
  26. std::string variable = *i;
  27. ++i;
  28. std::string output = "";
  29. // get the directory argument if there is one
  30. cmMakefile *dir = this->Makefile;
  31. if (*i == "DIRECTORY")
  32. {
  33. ++i;
  34. if (i == args.end())
  35. {
  36. this->SetError
  37. ("DIRECTORY argument provided without subsequent arguments");
  38. return false;
  39. }
  40. std::string sd = *i;
  41. // make sure the start dir is a full path
  42. if (!cmSystemTools::FileIsFullPath(sd.c_str()))
  43. {
  44. sd = this->Makefile->GetStartDirectory();
  45. sd += "/";
  46. sd += *i;
  47. }
  48. // lookup the makefile from the directory name
  49. cmLocalGenerator *lg =
  50. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  51. FindLocalGenerator(sd.c_str());
  52. if (!lg)
  53. {
  54. this->SetError
  55. ("DIRECTORY argument provided but requested directory not found. This could be because the directory argument was invalid or, 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 == "VARIABLES" || *i == "CACHE_VARIABLES" )
  64. {
  65. int cacheonly = 0;
  66. if ( *i == "CACHE_VARIABLES" )
  67. {
  68. cacheonly = 1;
  69. }
  70. std::vector<std::string> vars = dir->GetDefinitions(cacheonly);
  71. for ( cc = 0; cc < vars.size(); cc ++ )
  72. {
  73. if ( cc > 0 )
  74. {
  75. output += ";";
  76. }
  77. output += vars[cc];
  78. }
  79. }
  80. else if ( *i == "MACROS" )
  81. {
  82. dir->GetListOfMacros(output);
  83. }
  84. else if ( *i == "DEFINITIONS" )
  85. {
  86. output = dir->GetDefineFlags();
  87. }
  88. else if ( *i == "INCLUDE_DIRECTORIES" )
  89. {
  90. std::vector<std::string>::iterator it;
  91. int first = 1;
  92. cmOStringStream str;
  93. for ( it = dir->GetIncludeDirectories().begin();
  94. it != dir->GetIncludeDirectories().end();
  95. ++ it )
  96. {
  97. if ( !first )
  98. {
  99. str << ";";
  100. }
  101. str << it->c_str();
  102. first = 0;
  103. }
  104. output = str.str();
  105. }
  106. else if ( *i == "INCLUDE_REGULAR_EXPRESSION" )
  107. {
  108. output = dir->GetIncludeRegularExpression();
  109. }
  110. else if ( *i == "LINK_DIRECTORIES" )
  111. {
  112. std::vector<std::string>::iterator it;
  113. int first = 1;
  114. cmOStringStream str;
  115. for ( it = dir->GetLinkDirectories().begin();
  116. it != dir->GetLinkDirectories().end();
  117. ++ it )
  118. {
  119. if ( !first )
  120. {
  121. str << ";";
  122. }
  123. str << it->c_str();
  124. first = 0;
  125. }
  126. output = str.str();
  127. }
  128. else if ( *i == "DEFINITION" )
  129. {
  130. ++i;
  131. if (i == args.end())
  132. {
  133. this->SetError
  134. ("A request for a variable definition was made without providing the name of the variable to get.");
  135. return false;
  136. }
  137. output = dir->GetSafeDefinition(i->c_str());
  138. }
  139. else
  140. {
  141. const char *prop = dir->GetProperty(i->c_str());
  142. if (prop)
  143. {
  144. this->Makefile->AddDefinition(variable.c_str(), prop);
  145. return true;
  146. }
  147. this->Makefile->AddDefinition(variable.c_str(), "");
  148. return true;
  149. }
  150. this->Makefile->AddDefinition(variable.c_str(), output.c_str());
  151. return true;
  152. }