Imported Upstream version 2.8.9
[platform/upstream/cmake.git] / Source / cmSetTargetPropertiesCommand.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 "cmSetTargetPropertiesCommand.h"
13 #include "cmLocalGenerator.h"
14 #include "cmGlobalGenerator.h"
15
16 // cmSetTargetPropertiesCommand
17 bool cmSetTargetPropertiesCommand
18 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
19 {
20   if(args.size() < 2 )
21     {
22     this->SetError("called with incorrect number of arguments");
23     return false;
24     }
25
26   // first collect up the list of files
27   std::vector<std::string> propertyPairs;
28   bool doingFiles = true;
29   int numFiles = 0;
30   std::vector<std::string>::const_iterator j;
31   for(j= args.begin(); j != args.end();++j)
32     {
33     if(*j == "PROPERTIES")
34       {
35       doingFiles = false;
36       // now loop through the rest of the arguments, new style
37       ++j;
38       while (j != args.end())
39         {
40         propertyPairs.push_back(*j);
41         ++j;
42         if(j == args.end())
43           {
44           this->SetError("called with incorrect number of arguments.");
45           return false;
46           }
47         propertyPairs.push_back(*j);
48         ++j;
49         }
50       // break out of the loop because j is already == end
51       break;
52       }
53     else if (doingFiles)
54       {
55       numFiles++;
56       }
57     else
58       {
59       this->SetError("called with illegal arguments, maybe missing "
60                      "a PROPERTIES specifier?");
61       return false;
62       }
63     }
64   if(propertyPairs.size() == 0)
65     {
66      this->SetError("called with illegal arguments, maybe missing "
67                     "a PROPERTIES specifier?");
68      return false;
69     }
70   
71   // now loop over all the targets
72   int i;
73   for(i = 0; i < numFiles; ++i)
74     {   
75     bool ret = cmSetTargetPropertiesCommand::SetOneTarget
76       (args[i].c_str(),propertyPairs,this->Makefile);
77     if (!ret)
78       {
79       std::string message = "Can not find target to add properties to: ";
80       message += args[i];
81       this->SetError(message.c_str());
82       return false;
83       }
84     }
85   return true;
86 }
87
88 bool cmSetTargetPropertiesCommand
89 ::SetOneTarget(const char *tname, 
90                std::vector<std::string> &propertyPairs,
91                cmMakefile *mf)
92 {
93   if(cmTarget* target = mf->FindTargetToUse(tname))
94     {
95     // now loop through all the props and set them
96     unsigned int k;
97     for (k = 0; k < propertyPairs.size(); k = k + 2)
98       {
99       target->SetProperty(propertyPairs[k].c_str(),
100                           propertyPairs[k+1].c_str());
101       target->CheckProperty(propertyPairs[k].c_str(), mf);
102       }
103     }
104   // if file is not already in the makefile, then add it
105   else
106     { 
107     return false;
108     }
109   return true;
110 }