cmSetTestsPropertiesCommand.cxx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmSetTestsPropertiesCommand.h"
  11. #include "cmTest.h"
  12. #include "cmake.h"
  13. // cmSetTestsPropertiesCommand
  14. bool cmSetTestsPropertiesCommand::InitialPass(
  15. std::vector<std::string> const& args, cmExecutionStatus&)
  16. {
  17. if (args.empty()) {
  18. this->SetError("called with incorrect number of arguments");
  19. return false;
  20. }
  21. // first collect up the list of files
  22. std::vector<std::string> propertyPairs;
  23. int numFiles = 0;
  24. std::vector<std::string>::const_iterator j;
  25. for (j = args.begin(); j != args.end(); ++j) {
  26. if (*j == "PROPERTIES") {
  27. // now loop through the rest of the arguments, new style
  28. ++j;
  29. if (std::distance(j, args.end()) % 2 != 0) {
  30. this->SetError("called with incorrect number of arguments.");
  31. return false;
  32. }
  33. propertyPairs.insert(propertyPairs.end(), j, args.end());
  34. break;
  35. } else {
  36. numFiles++;
  37. }
  38. }
  39. if (propertyPairs.empty()) {
  40. this->SetError("called with illegal arguments, maybe "
  41. "missing a PROPERTIES specifier?");
  42. return false;
  43. }
  44. // now loop over all the targets
  45. int i;
  46. for (i = 0; i < numFiles; ++i) {
  47. std::string errors;
  48. bool ret = cmSetTestsPropertiesCommand::SetOneTest(args[i], propertyPairs,
  49. this->Makefile, errors);
  50. if (!ret) {
  51. this->SetError(errors);
  52. return ret;
  53. }
  54. }
  55. return true;
  56. }
  57. bool cmSetTestsPropertiesCommand::SetOneTest(
  58. const std::string& tname, std::vector<std::string>& propertyPairs,
  59. cmMakefile* mf, std::string& errors)
  60. {
  61. if (cmTest* test = mf->GetTest(tname)) {
  62. // now loop through all the props and set them
  63. unsigned int k;
  64. for (k = 0; k < propertyPairs.size(); k = k + 2) {
  65. if (!propertyPairs[k].empty()) {
  66. test->SetProperty(propertyPairs[k], propertyPairs[k + 1].c_str());
  67. }
  68. }
  69. } else {
  70. errors = "Can not find test to add properties to: ";
  71. errors += tname;
  72. return false;
  73. }
  74. return true;
  75. }