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