cmGetDirectoryPropertyCommand.cxx 4.3 KB

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