cmSetTestsPropertiesCommand.cxx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 "
  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. std::vector<cmTest*> &tests = *this->Makefile->GetTests();
  70. // now loop over all the targets
  71. int i;
  72. unsigned int k;
  73. for(i = 0; i < numFiles; ++i)
  74. {
  75. bool found = false;
  76. // if the file is already in the makefile just set properites on it
  77. std::vector<cmTest*>::iterator it;
  78. for ( it = tests.begin(); it != tests.end(); ++ it )
  79. {
  80. cmTest* test = *it;
  81. if ( test->GetName() == args[i] )
  82. {
  83. // now loop through all the props and set them
  84. for (k = 0; k < propertyPairs.size(); k = k + 2)
  85. {
  86. test->SetProperty(propertyPairs[k].c_str(),
  87. propertyPairs[k+1].c_str());
  88. }
  89. found = true;
  90. break;
  91. }
  92. }
  93. // if file is not already in the makefile, then add it
  94. if ( ! found )
  95. {
  96. std::string message = "Can not find test to add properties to: ";
  97. message += args[i];
  98. this->SetError(message.c_str());
  99. }
  100. }
  101. return true;
  102. }