ENH: mark some vars as advanced (and resort the list)
[cmake.git] / Source / cmSetSourceFilesPropertiesCommand.cxx
blob23ca71a6b96982ed4bd69b588c072bb98af79361
1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmSetSourceFilesPropertiesCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2002-08-26 12:53:16 $
7 Version: $Revision: 1.5 $
9 Copyright (c) 2002 Insight Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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 "cmSetSourceFilesPropertiesCommand.h"
19 // cmSetSourceFilesPropertiesCommand
20 bool cmSetSourceFilesPropertiesCommand::InitialPass(
21 std::vector<std::string> const& argsIn)
23 if(argsIn.size() < 2 )
25 this->SetError("called with incorrect number of arguments");
26 return false;
28 std::vector<std::string> args;
29 cmSystemTools::ExpandListArguments(argsIn, args);
31 // first collect up the list of files
32 std::vector<std::string> propertyPairs;
33 bool doingFiles = true;
34 int numFiles = 0;
35 std::vector<std::string>::const_iterator j;
36 for(j= args.begin(); j != args.end();++j)
38 // old style allows for specifier before PROPERTIES keyword
39 if(*j == "ABSTRACT")
41 doingFiles = false;
42 propertyPairs.push_back("ABSTRACT");
43 propertyPairs.push_back("1");
45 else if(*j == "WRAP_EXCLUDE")
47 doingFiles = false;
48 propertyPairs.push_back("WRAP_EXCLUDE");
49 propertyPairs.push_back("1");
51 else if(*j == "GENERATED")
53 doingFiles = false;
54 propertyPairs.push_back("GENERATED");
55 propertyPairs.push_back("1");
57 else if(*j == "COMPILE_FLAGS")
59 doingFiles = false;
60 propertyPairs.push_back("COMPILE_FLAGS");
61 ++j;
62 if(j == args.end())
64 this->SetError("called with incorrect number of arguments COMPILE_FLAGS with no flags");
65 return false;
67 propertyPairs.push_back(*j);
69 else if(*j == "PROPERTIES")
71 doingFiles = false;
72 // now loop through the rest of the arguments, new style
73 ++j;
74 while (j != args.end())
76 propertyPairs.push_back(*j);
77 ++j;
78 if(j == args.end())
80 this->SetError("called with incorrect number of arguments.");
81 return false;
83 propertyPairs.push_back(*j);
84 ++j;
86 // break out of the loop because j is already == end
87 break;
89 else if (doingFiles)
91 numFiles++;
93 else
95 this->SetError("called with illegal arguments, maybe missing a PROPERTIES specifier?");
96 return false;
100 // now loop over all the files
101 int i;
102 unsigned int k;
103 for(i = 0; i < numFiles; ++i)
105 // if the file is already in the makefile just set properites on it
106 cmSourceFile* sf = m_Makefile->GetSource(args[i].c_str());
107 if(sf)
109 // now loop through all the props and set them
110 for (k = 0; k < propertyPairs.size(); k = k + 2)
112 sf->SetProperty(propertyPairs[k].c_str(),propertyPairs[k+1].c_str());
115 // if file is not already in the makefile, then add it
116 else
118 std::string newfile = args[i];
119 cmSourceFile file;
120 std::string path = cmSystemTools::GetFilenamePath(newfile);
121 // now loop through all the props and set them
122 for (k = 0; k < propertyPairs.size(); k = k + 2)
124 file.SetProperty(propertyPairs[k].c_str(),propertyPairs[k+1].c_str());
126 if(file.GetPropertyAsBool("GENERATED"))
128 std::string ext = cmSystemTools::GetFilenameExtension(newfile);
129 std::string name_no_ext = cmSystemTools::GetFilenameName(newfile.c_str());
130 name_no_ext = name_no_ext.substr(0, name_no_ext.length()-ext.length());
131 if ( ext.length() && ext[0] == '.' )
133 ext = ext.substr(1);
135 if((path.size() && path[0] == '/') ||
136 (path.size() > 1 && path[1] == ':'))
138 file.SetName(name_no_ext.c_str(), path.c_str(), ext.c_str(), false);
140 else
142 file.SetName(name_no_ext.c_str(), m_Makefile->GetCurrentOutputDirectory(),
143 ext.c_str(), false);
146 else
148 // if this is a full path then
149 if((path.size() && path[0] == '/') ||
150 (path.size() > 1 && path[1] == ':'))
152 file.SetName(cmSystemTools::GetFilenameName(newfile.c_str()).c_str(),
153 path.c_str(),
154 m_Makefile->GetSourceExtensions(),
155 m_Makefile->GetHeaderExtensions());
157 else
159 file.SetName(newfile.c_str(), m_Makefile->GetCurrentDirectory(),
160 m_Makefile->GetSourceExtensions(),
161 m_Makefile->GetHeaderExtensions());
164 // add the source file to the makefile
165 m_Makefile->AddSource(file);
168 return true;