cmSetSourceFilesPropertiesCommand.cxx 4.4 KB

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