cmSetTestsPropertiesCommand.cxx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. while (j != args.end())
  35. {
  36. propertyPairs.push_back(*j);
  37. ++j;
  38. if(j == args.end())
  39. {
  40. this->SetError("called with incorrect number of arguments.");
  41. return false;
  42. }
  43. propertyPairs.push_back(*j);
  44. ++j;
  45. }
  46. // break out of the loop because j is already == end
  47. break;
  48. }
  49. else if (doingFiles)
  50. {
  51. numFiles++;
  52. }
  53. else
  54. {
  55. this->SetError("called with illegal arguments, maybe "
  56. "missing a PROPERTIES specifier?");
  57. return false;
  58. }
  59. }
  60. if(propertyPairs.empty())
  61. {
  62. this->SetError("called with illegal arguments, maybe "
  63. "missing a PROPERTIES specifier?");
  64. return false;
  65. }
  66. // now loop over all the targets
  67. int i;
  68. for(i = 0; i < numFiles; ++i)
  69. {
  70. std::string errors;
  71. bool ret =
  72. cmSetTestsPropertiesCommand::SetOneTest(args[i],
  73. propertyPairs,
  74. this->Makefile, errors);
  75. if (!ret)
  76. {
  77. this->SetError(errors);
  78. return ret;
  79. }
  80. }
  81. return true;
  82. }
  83. bool cmSetTestsPropertiesCommand
  84. ::SetOneTest(const std::string& tname,
  85. std::vector<std::string> &propertyPairs,
  86. cmMakefile *mf, std::string &errors)
  87. {
  88. if(cmTest* test = mf->GetTest(tname))
  89. {
  90. // now loop through all the props and set them
  91. unsigned int k;
  92. for (k = 0; k < propertyPairs.size(); k = k + 2)
  93. {
  94. test->SetProperty(propertyPairs[k],
  95. propertyPairs[k+1].c_str());
  96. }
  97. }
  98. else
  99. {
  100. errors = "Can not find test to add properties to: ";
  101. errors += tname;
  102. return false;
  103. }
  104. return true;
  105. }