cmSetSourceFilesPropertiesCommand.cxx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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
  17. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  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. while (j != propend)
  114. {
  115. propertyPairs.push_back(*j);
  116. if(*j == "GENERATED")
  117. {
  118. ++j;
  119. if(j != propend && cmSystemTools::IsOn(j->c_str()))
  120. {
  121. generated = true;
  122. }
  123. }
  124. else
  125. {
  126. ++j;
  127. }
  128. if(j == propend)
  129. {
  130. errors = "called with incorrect number of arguments.";
  131. return false;
  132. }
  133. propertyPairs.push_back(*j);
  134. ++j;
  135. }
  136. // break out of the loop because j is already == end
  137. break;
  138. }
  139. else
  140. {
  141. errors = "called with illegal arguments, maybe missing a "
  142. "PROPERTIES specifier?";
  143. return false;
  144. }
  145. }
  146. // now loop over all the files
  147. for(j= filebeg; j != fileend;++j)
  148. {
  149. // get the source file
  150. cmSourceFile* sf =
  151. mf->GetOrCreateSource(j->c_str(), generated);
  152. if(sf)
  153. {
  154. // now loop through all the props and set them
  155. unsigned int k;
  156. for (k = 0; k < propertyPairs.size(); k = k + 2)
  157. {
  158. sf->SetProperty(propertyPairs[k].c_str(),propertyPairs[k+1].c_str());
  159. }
  160. }
  161. }
  162. return true;
  163. }