cmGetPropertyCommand.cxx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 "cmGetPropertyCommand.h"
  14. #include "cmake.h"
  15. #include "cmTest.h"
  16. // cmGetPropertyCommand
  17. bool cmGetPropertyCommand::InitialPass(
  18. std::vector<std::string> const& args)
  19. {
  20. if(args.size() < 3 )
  21. {
  22. this->SetError("called with incorrect number of arguments");
  23. return false;
  24. }
  25. // the last argument in the property to get
  26. const char *property = args[args.size()-1].c_str();
  27. std::string output = "NOTFOUND";
  28. cmProperty::ScopeType scope;
  29. const char *scopeName = 0;
  30. if (args[1] == "GLOBAL" && args.size() == 3)
  31. {
  32. scope = cmProperty::GLOBAL;
  33. }
  34. else if (args[1] == "DIRECTORY" && args.size() >= 3)
  35. {
  36. scope = cmProperty::DIRECTORY;
  37. if (args.size() >= 4)
  38. {
  39. scopeName = args[2].c_str();
  40. }
  41. }
  42. else if (args[1] == "TARGET" && args.size() == 4)
  43. {
  44. scope = cmProperty::TARGET;
  45. scopeName = args[2].c_str();
  46. }
  47. else if (args[1] == "TEST" && args.size() == 4)
  48. {
  49. scope = cmProperty::TEST;
  50. scopeName = args[2].c_str();
  51. }
  52. else if (args[1] == "SOURCE_FILE" && args.size() == 4)
  53. {
  54. scope = cmProperty::SOURCE_FILE;
  55. scopeName = args[2].c_str();
  56. }
  57. else
  58. {
  59. this->SetError("called with illegal arguments.");
  60. return false;
  61. }
  62. switch (scope)
  63. {
  64. case cmProperty::TARGET:
  65. {
  66. cmTarget *tgt = this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
  67. ->FindTarget(0, scopeName, true);
  68. if (tgt)
  69. {
  70. cmTarget& target = *tgt;
  71. const char *prop = target.GetProperty(property);
  72. if (prop)
  73. {
  74. output = prop;
  75. }
  76. }
  77. }
  78. break;
  79. case cmProperty::DIRECTORY:
  80. {
  81. cmLocalGenerator *lg = this->Makefile->GetLocalGenerator();
  82. if (args.size() >= 4)
  83. {
  84. std::string sd = scopeName;
  85. // make sure the start dir is a full path
  86. if (!cmSystemTools::FileIsFullPath(sd.c_str()))
  87. {
  88. sd = this->Makefile->GetStartDirectory();
  89. sd += "/";
  90. sd += scopeName;
  91. }
  92. // The local generators are associated with collapsed paths.
  93. sd = cmSystemTools::CollapseFullPath(sd.c_str());
  94. // lookup the makefile from the directory name
  95. lg =
  96. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  97. FindLocalGenerator(sd.c_str());
  98. }
  99. if (!lg)
  100. {
  101. this->SetError
  102. ("DIRECTORY argument provided but requested directory not found. "
  103. "This could be because the directory argument was invalid or, "
  104. "it is valid but has not been processed yet.");
  105. return false;
  106. }
  107. const char *prop = lg->GetMakefile()->GetProperty(property);
  108. if (prop)
  109. {
  110. output = prop;
  111. }
  112. }
  113. break;
  114. case cmProperty::GLOBAL:
  115. {
  116. const char *prop =
  117. this->Makefile->GetCMakeInstance()->GetProperty(property);
  118. if (prop)
  119. {
  120. output = prop;
  121. }
  122. }
  123. break;
  124. case cmProperty::TEST:
  125. {
  126. cmTest *test = this->Makefile->GetTest(scopeName);
  127. const char *prop = test->GetProperty(property);
  128. if (prop)
  129. {
  130. output = prop;
  131. }
  132. }
  133. break;
  134. case cmProperty::SOURCE_FILE:
  135. {
  136. cmSourceFile* sf = this->Makefile->GetSource(scopeName);
  137. const char *prop = sf->GetProperty(property);
  138. if (prop)
  139. {
  140. output = prop;
  141. }
  142. }
  143. break;
  144. }
  145. this->Makefile->AddDefinition(args[0].c_str(), output.c_str());
  146. return true;
  147. }