cmSetTestsPropertiesCommand.cxx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 "cmSetTestsPropertiesCommand.h"
  4. #include <iterator>
  5. #include "cmMakefile.h"
  6. #include "cmTest.h"
  7. class cmExecutionStatus;
  8. // cmSetTestsPropertiesCommand
  9. bool cmSetTestsPropertiesCommand::InitialPass(
  10. std::vector<std::string> const& args, cmExecutionStatus&)
  11. {
  12. if (args.empty()) {
  13. this->SetError("called with incorrect number of arguments");
  14. return false;
  15. }
  16. // first collect up the list of files
  17. std::vector<std::string> propertyPairs;
  18. int numFiles = 0;
  19. std::vector<std::string>::const_iterator j;
  20. for (j = args.begin(); j != args.end(); ++j) {
  21. if (*j == "PROPERTIES") {
  22. // now loop through the rest of the arguments, new style
  23. ++j;
  24. if (std::distance(j, args.end()) % 2 != 0) {
  25. this->SetError("called with incorrect number of arguments.");
  26. return false;
  27. }
  28. propertyPairs.insert(propertyPairs.end(), j, args.end());
  29. break;
  30. }
  31. numFiles++;
  32. }
  33. if (propertyPairs.empty()) {
  34. this->SetError("called with illegal arguments, maybe "
  35. "missing a PROPERTIES specifier?");
  36. return false;
  37. }
  38. // now loop over all the targets
  39. int i;
  40. for (i = 0; i < numFiles; ++i) {
  41. std::string errors;
  42. bool ret = cmSetTestsPropertiesCommand::SetOneTest(args[i], propertyPairs,
  43. this->Makefile, errors);
  44. if (!ret) {
  45. this->SetError(errors);
  46. return ret;
  47. }
  48. }
  49. return true;
  50. }
  51. bool cmSetTestsPropertiesCommand::SetOneTest(
  52. const std::string& tname, std::vector<std::string>& propertyPairs,
  53. cmMakefile* mf, std::string& errors)
  54. {
  55. if (cmTest* test = mf->GetTest(tname)) {
  56. // now loop through all the props and set them
  57. unsigned int k;
  58. for (k = 0; k < propertyPairs.size(); k = k + 2) {
  59. if (!propertyPairs[k].empty()) {
  60. test->SetProperty(propertyPairs[k], propertyPairs[k + 1].c_str());
  61. }
  62. }
  63. } else {
  64. errors = "Can not find test to add properties to: ";
  65. errors += tname;
  66. return false;
  67. }
  68. return true;
  69. }