cmSetSourceFilesPropertiesCommand.cxx 3.9 KB

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