1
0

cmSetPropertiesCommand.cxx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 "cmSetPropertiesCommand.h"
  14. #include "cmSetTargetPropertiesCommand.h"
  15. #include "cmSetTestsPropertiesCommand.h"
  16. #include "cmSetSourceFilesPropertiesCommand.h"
  17. // cmSetPropertiesCommand
  18. bool cmSetPropertiesCommand::InitialPass(
  19. std::vector<std::string> const& args)
  20. {
  21. if(args.size() < 2 )
  22. {
  23. this->SetError("called with incorrect number of arguments");
  24. return false;
  25. }
  26. // first collect up the list of files
  27. std::vector<std::string> propertyPairs;
  28. bool doingFiles = true;
  29. int numFiles = 0;
  30. std::vector<std::string>::const_iterator j;
  31. for(j= args.begin(); j != args.end();++j)
  32. {
  33. if(*j == "PROPERTIES")
  34. {
  35. doingFiles = false;
  36. // now loop through the rest of the arguments, new style
  37. ++j;
  38. while (j != args.end())
  39. {
  40. propertyPairs.push_back(*j);
  41. ++j;
  42. if(j == args.end())
  43. {
  44. this->SetError("called with incorrect number of arguments.");
  45. return false;
  46. }
  47. propertyPairs.push_back(*j);
  48. ++j;
  49. }
  50. // break out of the loop because j is already == end
  51. break;
  52. }
  53. else if (doingFiles)
  54. {
  55. numFiles++;
  56. }
  57. else
  58. {
  59. this->SetError("called with illegal arguments, maybe missing "
  60. "a PROPERTIES specifier?");
  61. return false;
  62. }
  63. }
  64. if(propertyPairs.size() == 0)
  65. {
  66. this->SetError("called with illegal arguments, maybe missing "
  67. "a PROPERTIES specifier?");
  68. return false;
  69. }
  70. cmProperty::ScopeType scope;
  71. const char *scopeName = 0;
  72. if (args[0] == "GLOBAL" && numFiles == 1)
  73. {
  74. scope = cmProperty::GLOBAL;
  75. }
  76. else if (args[0] == "DIRECTORY" && numFiles == 1)
  77. {
  78. scope = cmProperty::DIRECTORY;
  79. }
  80. else if (args[0] == "TARGET" && numFiles == 2)
  81. {
  82. scope = cmProperty::TARGET;
  83. scopeName = args[1].c_str();
  84. }
  85. else if (args[0] == "TEST" && numFiles == 2)
  86. {
  87. scope = cmProperty::TEST;
  88. scopeName = args[1].c_str();
  89. }
  90. else if (args[0] == "SOURCE_FILE" && numFiles == 2)
  91. {
  92. scope = cmProperty::SOURCE_FILE;
  93. scopeName = args[1].c_str();
  94. }
  95. else
  96. {
  97. this->SetError("called with illegal arguments.");
  98. return false;
  99. }
  100. switch (scope)
  101. {
  102. case cmProperty::TARGET:
  103. {
  104. bool ret = cmSetTargetPropertiesCommand::
  105. SetOneTarget(scopeName,propertyPairs, this->Makefile);
  106. if (!ret)
  107. {
  108. std::string message = "Can not find target to add properties to: ";
  109. message += scopeName;
  110. this->SetError(message.c_str());
  111. return ret;
  112. }
  113. }
  114. break;
  115. case cmProperty::DIRECTORY:
  116. {
  117. std::string errors;
  118. bool ret =
  119. cmSetDirectoryPropertiesCommand::RunCommand(this->Makefile,
  120. args.begin() + 2,
  121. args.end(),
  122. errors);
  123. if (!ret)
  124. {
  125. this->SetError(errors.c_str());
  126. return ret;
  127. }
  128. }
  129. break;
  130. case cmProperty::GLOBAL:
  131. {
  132. for(j= propertyPairs.begin(); j != propertyPairs.end(); ++j)
  133. {
  134. this->Makefile->GetCMakeInstance()->SetProperty(j->c_str(),
  135. (++j)->c_str());
  136. }
  137. }
  138. break;
  139. case cmProperty::TEST:
  140. {
  141. std::string errors;
  142. bool ret = cmSetTestsPropertiesCommand::
  143. SetOneTest(scopeName,propertyPairs, this->Makefile, errors);
  144. if (!ret)
  145. {
  146. this->SetError(errors.c_str());
  147. return ret;
  148. }
  149. }
  150. break;
  151. case cmProperty::SOURCE_FILE:
  152. {
  153. std::string errors;
  154. bool ret = cmSetSourceFilesPropertiesCommand::
  155. RunCommand(this->Makefile,
  156. args.begin()+1, args.begin()+2,
  157. args.begin() + 2, args.end(),
  158. errors);
  159. if (!ret)
  160. {
  161. this->SetError(errors.c_str());
  162. }
  163. return ret;
  164. }
  165. break;
  166. }
  167. return true;
  168. }