cmSetTestsPropertiesCommand.cxx 2.9 KB

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