cmSetTestsPropertiesCommand.cxx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmSetTestsPropertiesCommand.h"
  14. #include "cmake.h"
  15. #include "cmTest.h"
  16. // cmSetTestsPropertiesCommand
  17. bool cmSetTestsPropertiesCommand
  18. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  19. {
  20. if(args.size() < 1 )
  21. {
  22. this->SetError("called with incorrect number of arguments");
  23. return false;
  24. }
  25. // first collect up the list of files
  26. std::vector<std::string> propertyPairs;
  27. bool doingFiles = true;
  28. int numFiles = 0;
  29. std::vector<std::string>::const_iterator j;
  30. for(j= args.begin(); j != args.end();++j)
  31. {
  32. if(*j == "PROPERTIES")
  33. {
  34. doingFiles = false;
  35. // now loop through the rest of the arguments, new style
  36. ++j;
  37. while (j != args.end())
  38. {
  39. propertyPairs.push_back(*j);
  40. ++j;
  41. if(j == args.end())
  42. {
  43. this->SetError("called with incorrect number of arguments.");
  44. return false;
  45. }
  46. propertyPairs.push_back(*j);
  47. ++j;
  48. }
  49. // break out of the loop because j is already == end
  50. break;
  51. }
  52. else if (doingFiles)
  53. {
  54. numFiles++;
  55. }
  56. else
  57. {
  58. this->SetError("called with illegal arguments, maybe "
  59. "missing a PROPERTIES specifier?");
  60. return false;
  61. }
  62. }
  63. if(propertyPairs.size() == 0)
  64. {
  65. this->SetError("called with illegal arguments, maybe "
  66. "missing a PROPERTIES specifier?");
  67. return false;
  68. }
  69. // now loop over all the targets
  70. int i;
  71. for(i = 0; i < numFiles; ++i)
  72. {
  73. std::string errors;
  74. bool ret =
  75. cmSetTestsPropertiesCommand::SetOneTest(args[i].c_str(),
  76. propertyPairs,
  77. this->Makefile, errors);
  78. if (!ret)
  79. {
  80. this->SetError(errors.c_str());
  81. return ret;
  82. }
  83. }
  84. return true;
  85. }
  86. bool cmSetTestsPropertiesCommand
  87. ::SetOneTest(const char *tname,
  88. std::vector<std::string> &propertyPairs,
  89. cmMakefile *mf, std::string &errors)
  90. {
  91. if(cmTest* test = mf->GetTest(tname))
  92. {
  93. // now loop through all the props and set them
  94. unsigned int k;
  95. for (k = 0; k < propertyPairs.size(); k = k + 2)
  96. {
  97. test->SetProperty(propertyPairs[k].c_str(),
  98. propertyPairs[k+1].c_str());
  99. }
  100. }
  101. else
  102. {
  103. errors = "Can not find test to add properties to: ";
  104. errors += tname;
  105. return false;
  106. }
  107. return true;
  108. }