cmSetSourceFilesPropertiesCommand.cxx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmSetSourceFilesPropertiesCommand.h"
  4. #include "cmSourceFile.h"
  5. #include "cmSystemTools.h"
  6. // cmSetSourceFilesPropertiesCommand
  7. bool cmSetSourceFilesPropertiesCommand::InitialPass(
  8. std::vector<std::string> const& args, cmExecutionStatus&)
  9. {
  10. if (args.size() < 2) {
  11. this->SetError("called with incorrect number of arguments");
  12. return false;
  13. }
  14. // break the arguments into source file names and properties
  15. int numFiles = 0;
  16. std::vector<std::string>::const_iterator j;
  17. j = args.begin();
  18. // old style allows for specifier before PROPERTIES keyword
  19. while (j != args.end() && *j != "ABSTRACT" && *j != "WRAP_EXCLUDE" &&
  20. *j != "GENERATED" && *j != "COMPILE_FLAGS" &&
  21. *j != "OBJECT_DEPENDS" && *j != "PROPERTIES") {
  22. numFiles++;
  23. ++j;
  24. }
  25. // now call the worker function
  26. std::string errors;
  27. bool ret = cmSetSourceFilesPropertiesCommand::RunCommand(
  28. this->Makefile, args.begin(), args.begin() + numFiles,
  29. args.begin() + numFiles, args.end(), errors);
  30. if (!ret) {
  31. this->SetError(errors);
  32. }
  33. return ret;
  34. }
  35. bool cmSetSourceFilesPropertiesCommand::RunCommand(
  36. cmMakefile* mf, std::vector<std::string>::const_iterator filebeg,
  37. std::vector<std::string>::const_iterator fileend,
  38. std::vector<std::string>::const_iterator propbeg,
  39. std::vector<std::string>::const_iterator propend, std::string& errors)
  40. {
  41. std::vector<std::string> propertyPairs;
  42. bool generated = false;
  43. std::vector<std::string>::const_iterator j;
  44. // build the property pairs
  45. for (j = propbeg; j != propend; ++j) {
  46. // old style allows for specifier before PROPERTIES keyword
  47. if (*j == "ABSTRACT") {
  48. propertyPairs.push_back("ABSTRACT");
  49. propertyPairs.push_back("1");
  50. } else if (*j == "WRAP_EXCLUDE") {
  51. propertyPairs.push_back("WRAP_EXCLUDE");
  52. propertyPairs.push_back("1");
  53. } else if (*j == "GENERATED") {
  54. generated = true;
  55. propertyPairs.push_back("GENERATED");
  56. propertyPairs.push_back("1");
  57. } else if (*j == "COMPILE_FLAGS") {
  58. propertyPairs.push_back("COMPILE_FLAGS");
  59. ++j;
  60. if (j == propend) {
  61. errors = "called with incorrect number of arguments "
  62. "COMPILE_FLAGS with no flags";
  63. return false;
  64. }
  65. propertyPairs.push_back(*j);
  66. } else if (*j == "OBJECT_DEPENDS") {
  67. propertyPairs.push_back("OBJECT_DEPENDS");
  68. ++j;
  69. if (j == propend) {
  70. errors = "called with incorrect number of arguments "
  71. "OBJECT_DEPENDS with no dependencies";
  72. return false;
  73. }
  74. propertyPairs.push_back(*j);
  75. } else if (*j == "PROPERTIES") {
  76. // now loop through the rest of the arguments, new style
  77. ++j;
  78. while (j != propend) {
  79. propertyPairs.push_back(*j);
  80. if (*j == "GENERATED") {
  81. ++j;
  82. if (j != propend && cmSystemTools::IsOn(j->c_str())) {
  83. generated = true;
  84. }
  85. } else {
  86. ++j;
  87. }
  88. if (j == propend) {
  89. errors = "called with incorrect number of arguments.";
  90. return false;
  91. }
  92. propertyPairs.push_back(*j);
  93. ++j;
  94. }
  95. // break out of the loop because j is already == end
  96. break;
  97. } else {
  98. errors = "called with illegal arguments, maybe missing a "
  99. "PROPERTIES specifier?";
  100. return false;
  101. }
  102. }
  103. // now loop over all the files
  104. for (j = filebeg; j != fileend; ++j) {
  105. // get the source file
  106. cmSourceFile* sf = mf->GetOrCreateSource(*j, generated);
  107. if (sf) {
  108. // now loop through all the props and set them
  109. unsigned int k;
  110. for (k = 0; k < propertyPairs.size(); k = k + 2) {
  111. sf->SetProperty(propertyPairs[k], propertyPairs[k + 1].c_str());
  112. }
  113. }
  114. }
  115. return true;
  116. }