cmGetDirectoryPropertyCommand.cxx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. "
  56. "This could be because the directory argument was invalid or, "
  57. "it is valid but has not been processed yet.");
  58. return false;
  59. }
  60. dir = lg->GetMakefile();
  61. ++i;
  62. }
  63. // OK, now we have the directory to process, we just get the requested
  64. // information out of it
  65. if ( *i == "VARIABLES" || *i == "CACHE_VARIABLES" )
  66. {
  67. int cacheonly = 0;
  68. if ( *i == "CACHE_VARIABLES" )
  69. {
  70. cacheonly = 1;
  71. }
  72. std::vector<std::string> vars = dir->GetDefinitions(cacheonly);
  73. for ( cc = 0; cc < vars.size(); cc ++ )
  74. {
  75. if ( cc > 0 )
  76. {
  77. output += ";";
  78. }
  79. output += vars[cc];
  80. }
  81. }
  82. else if ( *i == "MACROS" )
  83. {
  84. dir->GetListOfMacros(output);
  85. }
  86. else if ( *i == "DEFINITIONS" )
  87. {
  88. output = dir->GetDefineFlags();
  89. }
  90. else if ( *i == "INCLUDE_DIRECTORIES" )
  91. {
  92. std::vector<std::string>::iterator it;
  93. int first = 1;
  94. cmOStringStream str;
  95. for ( it = dir->GetIncludeDirectories().begin();
  96. it != dir->GetIncludeDirectories().end();
  97. ++ it )
  98. {
  99. if ( !first )
  100. {
  101. str << ";";
  102. }
  103. str << it->c_str();
  104. first = 0;
  105. }
  106. output = str.str();
  107. }
  108. else if ( *i == "INCLUDE_REGULAR_EXPRESSION" )
  109. {
  110. output = dir->GetIncludeRegularExpression();
  111. }
  112. else if ( *i == "LINK_DIRECTORIES" )
  113. {
  114. std::vector<std::string>::iterator it;
  115. int first = 1;
  116. cmOStringStream str;
  117. for ( it = dir->GetLinkDirectories().begin();
  118. it != dir->GetLinkDirectories().end();
  119. ++ it )
  120. {
  121. if ( !first )
  122. {
  123. str << ";";
  124. }
  125. str << it->c_str();
  126. first = 0;
  127. }
  128. output = str.str();
  129. }
  130. else if ( *i == "DEFINITION" )
  131. {
  132. ++i;
  133. if (i == args.end())
  134. {
  135. this->SetError("A request for a variable definition was made without "
  136. "providing the name of the variable to get.");
  137. return false;
  138. }
  139. output = dir->GetSafeDefinition(i->c_str());
  140. }
  141. else
  142. {
  143. const char *prop = dir->GetProperty(i->c_str());
  144. if (prop)
  145. {
  146. this->Makefile->AddDefinition(variable.c_str(), prop);
  147. return true;
  148. }
  149. this->Makefile->AddDefinition(variable.c_str(), "");
  150. return true;
  151. }
  152. this->Makefile->AddDefinition(variable.c_str(), output.c_str());
  153. return true;
  154. }