ENH: add target properties files
[cmake.git] / Source / cmSetTargetPropertiesCommand.cxx
blob02feed871142666c72168f010534f28e7e36241e
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmSetTargetPropertiesCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2002-12-21 16:14:47 $
7 Version: $Revision: 1.1 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmSetTargetPropertiesCommand.h"
19 // cmSetTargetPropertiesCommand
20 bool cmSetTargetPropertiesCommand::InitialPass(
21 std::vector<std::string> const& args)
23 if(args.size() < 2 )
25 this->SetError("called with incorrect number of arguments");
26 return false;
29 // first collect up the list of files
30 std::vector<std::string> propertyPairs;
31 bool doingFiles = true;
32 int numFiles = 0;
33 std::vector<std::string>::const_iterator j;
34 for(j= args.begin(); j != args.end();++j)
36 if(*j == "PROPERTIES")
38 doingFiles = false;
39 // now loop through the rest of the arguments, new style
40 ++j;
41 while (j != args.end())
43 propertyPairs.push_back(*j);
44 ++j;
45 if(j == args.end())
47 this->SetError("called with incorrect number of arguments.");
48 return false;
50 propertyPairs.push_back(*j);
51 ++j;
53 // break out of the loop because j is already == end
54 break;
56 else if (doingFiles)
58 numFiles++;
60 else
62 this->SetError("called with illegal arguments, maybe missing a PROPERTIES specifier?");
63 return false;
66 if(propertyPairs.size() == 0)
68 this->SetError("called with illegal arguments, maybe missing a PROPERTIES specifier?");
69 return false;
72 cmTargets& targets = m_Makefile->GetTargets();
73 // now loop over all the targets
74 int i;
75 unsigned int k;
76 for(i = 0; i < numFiles; ++i)
78 // if the file is already in the makefile just set properites on it
79 cmTargets::iterator t = targets.find(args[i]);
80 if ( t != targets.end())
82 cmTarget& target = t->second;
83 // now loop through all the props and set them
84 for (k = 0; k < propertyPairs.size(); k = k + 2)
86 target.SetProperty(propertyPairs[k].c_str(),propertyPairs[k+1].c_str());
89 // if file is not already in the makefile, then add it
90 else
92 std::string message = "Can not find target to add properties to: ";
93 message += args[i];
94 this->SetError(message.c_str());
97 return true;