cmSetSourceFilesPropertiesCommand.cxx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmSetSourceFilesPropertiesCommand.h"
  11. #include "cmSourceFile.h"
  12. // cmSetSourceFilesPropertiesCommand
  13. bool cmSetSourceFilesPropertiesCommand
  14. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  15. {
  16. if(args.size() < 2 )
  17. {
  18. this->SetError("called with incorrect number of arguments");
  19. return false;
  20. }
  21. // break the arguments into source file names and properties
  22. int numFiles = 0;
  23. std::vector<std::string>::const_iterator j;
  24. j = args.begin();
  25. // old style allows for specifier before PROPERTIES keyword
  26. while (j != args.end() &&
  27. *j != "ABSTRACT" &&
  28. *j != "WRAP_EXCLUDE" &&
  29. *j != "GENERATED" &&
  30. *j != "COMPILE_FLAGS" &&
  31. *j != "OBJECT_DEPENDS" &&
  32. *j != "PROPERTIES")
  33. {
  34. numFiles++;
  35. ++j;
  36. }
  37. // now call the worker function
  38. std::string errors;
  39. bool ret =
  40. cmSetSourceFilesPropertiesCommand
  41. ::RunCommand(this->Makefile,
  42. args.begin(),
  43. args.begin() + numFiles,
  44. args.begin() + numFiles,
  45. args.end(), errors);
  46. if (!ret)
  47. {
  48. this->SetError(errors.c_str());
  49. }
  50. return ret;
  51. }
  52. bool cmSetSourceFilesPropertiesCommand
  53. ::RunCommand(cmMakefile *mf,
  54. std::vector<std::string>::const_iterator filebeg,
  55. std::vector<std::string>::const_iterator fileend,
  56. std::vector<std::string>::const_iterator propbeg,
  57. std::vector<std::string>::const_iterator propend,
  58. std::string &errors)
  59. {
  60. std::vector<std::string> propertyPairs;
  61. bool generated = false;
  62. std::vector<std::string>::const_iterator j;
  63. // build the property pairs
  64. for(j= propbeg; j != propend;++j)
  65. {
  66. // old style allows for specifier before PROPERTIES keyword
  67. if(*j == "ABSTRACT")
  68. {
  69. propertyPairs.push_back("ABSTRACT");
  70. propertyPairs.push_back("1");
  71. }
  72. else if(*j == "WRAP_EXCLUDE")
  73. {
  74. propertyPairs.push_back("WRAP_EXCLUDE");
  75. propertyPairs.push_back("1");
  76. }
  77. else if(*j == "GENERATED")
  78. {
  79. generated = true;
  80. propertyPairs.push_back("GENERATED");
  81. propertyPairs.push_back("1");
  82. }
  83. else if(*j == "COMPILE_FLAGS")
  84. {
  85. propertyPairs.push_back("COMPILE_FLAGS");
  86. ++j;
  87. if(j == propend)
  88. {
  89. errors = "called with incorrect number of arguments "
  90. "COMPILE_FLAGS with no flags";
  91. return false;
  92. }
  93. propertyPairs.push_back(*j);
  94. }
  95. else if(*j == "OBJECT_DEPENDS")
  96. {
  97. propertyPairs.push_back("OBJECT_DEPENDS");
  98. ++j;
  99. if(j == propend)
  100. {
  101. errors = "called with incorrect number of arguments "
  102. "OBJECT_DEPENDS with no dependencies";
  103. return false;
  104. }
  105. propertyPairs.push_back(*j);
  106. }
  107. else if(*j == "PROPERTIES")
  108. {
  109. // now loop through the rest of the arguments, new style
  110. ++j;
  111. while (j != propend)
  112. {
  113. propertyPairs.push_back(*j);
  114. if(*j == "GENERATED")
  115. {
  116. ++j;
  117. if(j != propend && cmSystemTools::IsOn(j->c_str()))
  118. {
  119. generated = true;
  120. }
  121. }
  122. else
  123. {
  124. ++j;
  125. }
  126. if(j == propend)
  127. {
  128. errors = "called with incorrect number of arguments.";
  129. return false;
  130. }
  131. propertyPairs.push_back(*j);
  132. ++j;
  133. }
  134. // break out of the loop because j is already == end
  135. break;
  136. }
  137. else
  138. {
  139. errors = "called with illegal arguments, maybe missing a "
  140. "PROPERTIES specifier?";
  141. return false;
  142. }
  143. }
  144. // now loop over all the files
  145. for(j= filebeg; j != fileend;++j)
  146. {
  147. // get the source file
  148. cmSourceFile* sf =
  149. mf->GetOrCreateSource(j->c_str(), generated);
  150. if(sf)
  151. {
  152. // now loop through all the props and set them
  153. unsigned int k;
  154. for (k = 0; k < propertyPairs.size(); k = k + 2)
  155. {
  156. sf->SetProperty(propertyPairs[k].c_str(),propertyPairs[k+1].c_str());
  157. }
  158. }
  159. }
  160. return true;
  161. }