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.

199 lines
5.5 KiB

22 years ago
23 years ago
  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 "cmSetSourceFilesPropertiesCommand.h"
  14. #include "cmSourceFile.h"
  15. // cmSetSourceFilesPropertiesCommand
  16. bool cmSetSourceFilesPropertiesCommand::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. // break the arguments into source file names and properties
  25. int numFiles = 0;
  26. std::vector<std::string>::const_iterator j;
  27. j = args.begin();
  28. // old style allows for specifier before PROPERTIES keyword
  29. while (*j != "ABSTRACT" &&
  30. *j != "WRAP_EXCLUDE" &&
  31. *j != "GENERATED" &&
  32. *j != "COMPILE_FLAGS" &&
  33. *j != "OBJECT_DEPENDS" &&
  34. *j != "PROPERTIES")
  35. {
  36. numFiles++;
  37. ++j;
  38. }
  39. // now call the worker function
  40. std::string errors;
  41. bool ret =
  42. cmSetSourceFilesPropertiesCommand
  43. ::RunCommand(this->Makefile,
  44. args.begin(),
  45. args.begin() + numFiles,
  46. args.begin() + numFiles,
  47. args.end(), errors);
  48. if (!ret)
  49. {
  50. this->SetError(errors.c_str());
  51. }
  52. return ret;
  53. }
  54. bool cmSetSourceFilesPropertiesCommand
  55. ::RunCommand(cmMakefile *mf,
  56. std::vector<std::string>::const_iterator filebeg,
  57. std::vector<std::string>::const_iterator fileend,
  58. std::vector<std::string>::const_iterator propbeg,
  59. std::vector<std::string>::const_iterator propend,
  60. std::string &errors)
  61. {
  62. std::vector<std::string> propertyPairs;
  63. bool generated = false;
  64. std::vector<std::string>::const_iterator j;
  65. // build the property pairs
  66. for(j= propbeg; j != propend;++j)
  67. {
  68. // old style allows for specifier before PROPERTIES keyword
  69. if(*j == "ABSTRACT")
  70. {
  71. propertyPairs.push_back("ABSTRACT");
  72. propertyPairs.push_back("1");
  73. }
  74. else if(*j == "WRAP_EXCLUDE")
  75. {
  76. propertyPairs.push_back("WRAP_EXCLUDE");
  77. propertyPairs.push_back("1");
  78. }
  79. else if(*j == "GENERATED")
  80. {
  81. generated = true;
  82. propertyPairs.push_back("GENERATED");
  83. propertyPairs.push_back("1");
  84. }
  85. else if(*j == "COMPILE_FLAGS")
  86. {
  87. propertyPairs.push_back("COMPILE_FLAGS");
  88. ++j;
  89. if(j == propend)
  90. {
  91. errors = "called with incorrect number of arguments "
  92. "COMPILE_FLAGS with no flags";
  93. return false;
  94. }
  95. propertyPairs.push_back(*j);
  96. }
  97. else if(*j == "OBJECT_DEPENDS")
  98. {
  99. propertyPairs.push_back("OBJECT_DEPENDS");
  100. ++j;
  101. if(j == propend)
  102. {
  103. errors = "called with incorrect number of arguments "
  104. "OBJECT_DEPENDS with no dependencies";
  105. return false;
  106. }
  107. propertyPairs.push_back(*j);
  108. }
  109. else if(*j == "PROPERTIES")
  110. {
  111. // now loop through the rest of the arguments, new style
  112. ++j;
  113. bool dontPush = false;
  114. while (j != propend)
  115. {
  116. propertyPairs.push_back(*j);
  117. if(*j == "GENERATED")
  118. {
  119. ++j;
  120. if(j != propend && cmSystemTools::IsOn(j->c_str()))
  121. {
  122. generated = true;
  123. }
  124. }
  125. else if(*j == "MACOSX_PACKAGE_LOCATION")
  126. {
  127. ++j;
  128. if(j == propend)
  129. {
  130. errors = "called with incorrect number of arguments "
  131. "MACOSX_PACKAGE_LOCATION with no flags";
  132. return false;
  133. }
  134. propertyPairs.push_back(*j);
  135. propertyPairs.push_back("EXTRA_CONTENT");
  136. propertyPairs.push_back("1");
  137. propertyPairs.push_back("MACOSX_CONTENT");
  138. propertyPairs.push_back("1");
  139. propertyPairs.push_back("KEEP_EXTENSION");
  140. propertyPairs.push_back("1");
  141. propertyPairs.push_back("LANGUAGE");
  142. propertyPairs.push_back("MacOSX_Content");
  143. dontPush = true;
  144. }
  145. else
  146. {
  147. ++j;
  148. }
  149. if(j == propend)
  150. {
  151. errors = "called with incorrect number of arguments.";
  152. return false;
  153. }
  154. if ( !dontPush )
  155. {
  156. propertyPairs.push_back(*j);
  157. }
  158. ++j;
  159. dontPush = false;
  160. }
  161. // break out of the loop because j is already == end
  162. break;
  163. }
  164. else
  165. {
  166. errors = "called with illegal arguments, maybe missing a "
  167. "PROPERTIES specifier?";
  168. return false;
  169. }
  170. }
  171. // now loop over all the files
  172. for(j= filebeg; j != fileend;++j)
  173. {
  174. // get the source file
  175. cmSourceFile* sf =
  176. mf->GetOrCreateSource(j->c_str(), generated);
  177. if(sf)
  178. {
  179. // now loop through all the props and set them
  180. unsigned int k;
  181. for (k = 0; k < propertyPairs.size(); k = k + 2)
  182. {
  183. sf->SetProperty(propertyPairs[k].c_str(),propertyPairs[k+1].c_str());
  184. }
  185. }
  186. }
  187. return true;
  188. }