1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmSetSourceFilesPropertiesCommand.cxx,v $
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");
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;
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
42 propertyPairs
.push_back("ABSTRACT");
43 propertyPairs
.push_back("1");
45 else if(*j
== "WRAP_EXCLUDE")
48 propertyPairs
.push_back("WRAP_EXCLUDE");
49 propertyPairs
.push_back("1");
51 else if(*j
== "GENERATED")
54 propertyPairs
.push_back("GENERATED");
55 propertyPairs
.push_back("1");
57 else if(*j
== "COMPILE_FLAGS")
60 propertyPairs
.push_back("COMPILE_FLAGS");
64 this->SetError("called with incorrect number of arguments COMPILE_FLAGS with no flags");
67 propertyPairs
.push_back(*j
);
69 else if(*j
== "PROPERTIES")
72 // now loop through the rest of the arguments, new style
74 while (j
!= args
.end())
76 propertyPairs
.push_back(*j
);
80 this->SetError("called with incorrect number of arguments.");
83 propertyPairs
.push_back(*j
);
86 // break out of the loop because j is already == end
95 this->SetError("called with illegal arguments, maybe missing a PROPERTIES specifier?");
100 // now loop over all the files
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());
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
118 std::string newfile
= args
[i
];
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] == '.' )
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);
142 file
.SetName(name_no_ext
.c_str(), m_Makefile
->GetCurrentOutputDirectory(),
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(),
154 m_Makefile
->GetSourceExtensions(),
155 m_Makefile
->GetHeaderExtensions());
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
);