cmSetTestsPropertiesCommand.cxx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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::InitialPass(
  18. std::vector<std::string> const& args)
  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 missing a PROPERTIES specifier?");
  59. return false;
  60. }
  61. }
  62. if(propertyPairs.size() == 0)
  63. {
  64. this->SetError("called with illegal arguments, maybe missing a PROPERTIES specifier?");
  65. return false;
  66. }
  67. std::vector<cmTest*> &tests = *m_Makefile->GetTests();
  68. // now loop over all the targets
  69. int i;
  70. unsigned int k;
  71. for(i = 0; i < numFiles; ++i)
  72. {
  73. bool found = false;
  74. // if the file is already in the makefile just set properites on it
  75. std::vector<cmTest*>::iterator it;
  76. for ( it = tests.begin(); it != tests.end(); ++ it )
  77. {
  78. cmTest* test = *it;
  79. if ( test->GetName() == args[i] )
  80. {
  81. // now loop through all the props and set them
  82. for (k = 0; k < propertyPairs.size(); k = k + 2)
  83. {
  84. test->SetProperty(propertyPairs[k].c_str(),propertyPairs[k+1].c_str());
  85. }
  86. found = true;
  87. break;
  88. }
  89. }
  90. // if file is not already in the makefile, then add it
  91. if ( ! found )
  92. {
  93. std::string message = "Can not find test to add properties to: ";
  94. message += args[i];
  95. this->SetError(message.c_str());
  96. }
  97. }
  98. return true;
  99. }