You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
5.6 KiB

  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. if (numFiles == 2)
  80. {
  81. scopeName = args[1].c_str();
  82. }
  83. }
  84. else if (args[0] == "TARGET" && numFiles == 2)
  85. {
  86. scope = cmProperty::TARGET;
  87. scopeName = args[1].c_str();
  88. }
  89. else if (args[0] == "TEST" && numFiles == 2)
  90. {
  91. scope = cmProperty::TEST;
  92. scopeName = args[1].c_str();
  93. }
  94. else if (args[0] == "SOURCE_FILE" && numFiles == 2)
  95. {
  96. scope = cmProperty::SOURCE_FILE;
  97. scopeName = args[1].c_str();
  98. }
  99. else
  100. {
  101. this->SetError("called with illegal arguments.");
  102. return false;
  103. }
  104. switch (scope)
  105. {
  106. case cmProperty::TARGET:
  107. {
  108. bool ret = cmSetTargetPropertiesCommand::
  109. SetOneTarget(scopeName,propertyPairs, this->Makefile);
  110. if (!ret)
  111. {
  112. std::string message = "Can not find target to add properties to: ";
  113. message += scopeName;
  114. this->SetError(message.c_str());
  115. return ret;
  116. }
  117. }
  118. break;
  119. case cmProperty::DIRECTORY:
  120. {
  121. // lookup the makefile from the directory name
  122. cmLocalGenerator *lg = this->Makefile->GetLocalGenerator();
  123. if (numFiles == 2)
  124. {
  125. std::string sd = scopeName;
  126. // make sure the start dir is a full path
  127. if (!cmSystemTools::FileIsFullPath(sd.c_str()))
  128. {
  129. sd = this->Makefile->GetStartDirectory();
  130. sd += "/";
  131. sd += scopeName;
  132. }
  133. // The local generators are associated with collapsed paths.
  134. sd = cmSystemTools::CollapseFullPath(sd.c_str());
  135. lg = this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  136. FindLocalGenerator(sd.c_str());
  137. }
  138. if (!lg)
  139. {
  140. this->SetError
  141. ("DIRECTORY argument provided but requested directory not found. "
  142. "This could be because the directory argument was invalid or, "
  143. "it is valid but has not been processed yet.");
  144. return false;
  145. }
  146. for(j= propertyPairs.begin(); j != propertyPairs.end(); ++j)
  147. {
  148. const char *pn = j->c_str();
  149. ++j;
  150. lg->GetMakefile()->SetProperty(pn,j->c_str());
  151. }
  152. }
  153. break;
  154. case cmProperty::GLOBAL:
  155. {
  156. for(j= propertyPairs.begin(); j != propertyPairs.end(); ++j)
  157. {
  158. const char *pn = j->c_str();
  159. ++j;
  160. this->Makefile->GetCMakeInstance()->SetProperty(pn, j->c_str());
  161. }
  162. }
  163. break;
  164. case cmProperty::TEST:
  165. {
  166. std::string errors;
  167. bool ret = cmSetTestsPropertiesCommand::
  168. SetOneTest(scopeName,propertyPairs, this->Makefile, errors);
  169. if (!ret)
  170. {
  171. this->SetError(errors.c_str());
  172. return ret;
  173. }
  174. }
  175. break;
  176. case cmProperty::SOURCE_FILE:
  177. {
  178. std::string errors;
  179. bool ret = cmSetSourceFilesPropertiesCommand::
  180. RunCommand(this->Makefile,
  181. args.begin()+1, args.begin()+2,
  182. args.begin() + 2, args.end(),
  183. errors);
  184. if (!ret)
  185. {
  186. this->SetError(errors.c_str());
  187. return ret;
  188. }
  189. }
  190. break;
  191. case cmProperty::VARIABLE:
  192. case cmProperty::CACHED_VARIABLE:
  193. // not handled by SetProperty
  194. break;
  195. }
  196. return true;
  197. }