STYLE: Nightly Date Stamp
[cmake.git] / Source / cmInstallGenerator.cxx
blob53c98cf30f2803dfa72fc47902aecf23309644fa
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmInstallGenerator.cxx,v $
5 Language: C++
6 Date: $Date: 2008-01-28 13:38:35 $
7 Version: $Revision: 1.15 $
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 "cmInstallGenerator.h"
19 #include "cmSystemTools.h"
20 #include "cmTarget.h"
22 //----------------------------------------------------------------------------
23 cmInstallGenerator
24 ::cmInstallGenerator(const char* destination,
25 std::vector<std::string> const& configurations,
26 const char* component):
27 Destination(destination? destination:""),
28 Configurations(configurations),
29 Component(component? component:""),
30 ConfigurationName(0),
31 ConfigurationTypes(0)
35 //----------------------------------------------------------------------------
36 cmInstallGenerator
37 ::~cmInstallGenerator()
41 //----------------------------------------------------------------------------
42 void
43 cmInstallGenerator
44 ::Generate(std::ostream& os, const char* config,
45 std::vector<std::string> const& configurationTypes)
47 this->ConfigurationName = config;
48 this->ConfigurationTypes = &configurationTypes;
49 this->GenerateScript(os);
50 this->ConfigurationName = 0;
51 this->ConfigurationTypes = 0;
54 //----------------------------------------------------------------------------
55 void cmInstallGenerator
56 ::AddInstallRule(
57 std::ostream& os,
58 int type,
59 std::vector<std::string> const& files,
60 bool optional /* = false */,
61 const char* properties /* = 0 */,
62 const char* permissions_file /* = 0 */,
63 const char* permissions_dir /* = 0 */,
64 const char* rename /* = 0 */,
65 const char* literal_args /* = 0 */,
66 cmInstallGeneratorIndent const& indent
69 // Use the FILE command to install the file.
70 std::string stype;
71 switch(type)
73 case cmTarget::INSTALL_DIRECTORY:stype = "DIRECTORY"; break;
74 case cmTarget::INSTALL_PROGRAMS: stype = "PROGRAM"; break;
75 case cmTarget::EXECUTABLE: stype = "EXECUTABLE"; break;
76 case cmTarget::STATIC_LIBRARY: stype = "STATIC_LIBRARY"; break;
77 case cmTarget::SHARED_LIBRARY: stype = "SHARED_LIBRARY"; break;
78 case cmTarget::MODULE_LIBRARY: stype = "MODULE"; break;
79 case cmTarget::INSTALL_FILES:
80 default: stype = "FILE"; break;
82 os << indent;
83 std::string dest = this->GetInstallDestination();
84 os << "FILE(INSTALL DESTINATION \"" << dest << "\" TYPE " << stype.c_str();
85 if(optional)
87 os << " OPTIONAL";
89 if(properties && *properties)
91 os << " PROPERTIES" << properties;
93 if(permissions_file && *permissions_file)
95 os << " PERMISSIONS" << permissions_file;
97 if(permissions_dir && *permissions_dir)
99 os << " DIR_PERMISSIONS" << permissions_dir;
101 if(rename && *rename)
103 os << " RENAME \"" << rename << "\"";
105 os << " FILES";
106 if(files.size() == 1)
108 os << " \"" << files[0] << "\"";
110 else
112 for(std::vector<std::string>::const_iterator fi = files.begin();
113 fi != files.end(); ++fi)
115 os << "\n" << indent << " \"" << *fi << "\"";
117 os << "\n" << indent << " ";
118 if(!(literal_args && *literal_args))
120 os << " ";
123 if(literal_args && *literal_args)
125 os << literal_args;
127 os << ")\n";
130 //----------------------------------------------------------------------------
131 static void cmInstallGeneratorEncodeConfig(const char* config,
132 std::string& result)
134 for(const char* c = config; *c; ++c)
136 if(*c >= 'a' && *c <= 'z')
138 result += "[";
139 result += *c + ('A' - 'a');
140 result += *c;
141 result += "]";
143 else if(*c >= 'A' && *c <= 'Z')
145 result += "[";
146 result += *c;
147 result += *c + ('a' - 'A');
148 result += "]";
150 else
152 result += *c;
157 //----------------------------------------------------------------------------
158 std::string
159 cmInstallGenerator::CreateConfigTest(const char* config)
161 std::string result = "\"${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^(";
162 if(config && *config)
164 cmInstallGeneratorEncodeConfig(config, result);
166 result += ")$\"";
167 return result;
170 //----------------------------------------------------------------------------
171 std::string
172 cmInstallGenerator::CreateConfigTest(std::vector<std::string> const& configs)
174 std::string result = "\"${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^(";
175 const char* sep = "";
176 for(std::vector<std::string>::const_iterator ci = configs.begin();
177 ci != configs.end(); ++ci)
179 result += sep;
180 sep = "|";
181 cmInstallGeneratorEncodeConfig(ci->c_str(), result);
183 result += ")$\"";
184 return result;
187 //----------------------------------------------------------------------------
188 std::string
189 cmInstallGenerator::CreateComponentTest(const char* component)
191 std::string result = "NOT CMAKE_INSTALL_COMPONENT OR "
192 "\"${CMAKE_INSTALL_COMPONENT}\" MATCHES \"^(";
193 result += component;
194 result += ")$\"";
195 return result;
198 //----------------------------------------------------------------------------
199 void cmInstallGenerator::GenerateScript(std::ostream& os)
201 // Track indentation.
202 Indent indent;
204 // Begin this block of installation.
205 std::string component_test =
206 this->CreateComponentTest(this->Component.c_str());
207 os << indent << "IF(" << component_test << ")\n";
209 // Generate the script possibly with per-configuration code.
210 this->GenerateScriptConfigs(os, indent.Next());
212 // End this block of installation.
213 os << indent << "ENDIF(" << component_test << ")\n\n";
216 //----------------------------------------------------------------------------
217 void
218 cmInstallGenerator::GenerateScriptConfigs(std::ostream& os,
219 Indent const& indent)
221 if(this->Configurations.empty())
223 // This rule is for all configurations.
224 this->GenerateScriptActions(os, indent);
226 else
228 // Generate a per-configuration block.
229 std::string config_test = this->CreateConfigTest(this->Configurations);
230 os << indent << "IF(" << config_test << ")\n";
231 this->GenerateScriptActions(os, indent.Next());
232 os << indent << "ENDIF(" << config_test << ")\n";
236 //----------------------------------------------------------------------------
237 void cmInstallGenerator::GenerateScriptActions(std::ostream&, Indent const&)
239 // No actions for this generator.
242 //----------------------------------------------------------------------------
243 bool cmInstallGenerator::InstallsForConfig(const char* config)
245 // If this is not a configuration-specific rule then we install.
246 if(this->Configurations.empty())
248 return true;
251 // This is a configuration-specific rule. Check if the config
252 // matches this rule.
253 std::string config_upper = cmSystemTools::UpperCase(config?config:"");
254 for(std::vector<std::string>::const_iterator i =
255 this->Configurations.begin();
256 i != this->Configurations.end(); ++i)
258 if(cmSystemTools::UpperCase(*i) == config_upper)
260 return true;
263 return false;
266 //----------------------------------------------------------------------------
267 std::string cmInstallGenerator::GetInstallDestination() const
269 std::string result;
270 if(!this->Destination.empty() &&
271 !cmSystemTools::FileIsFullPath(this->Destination.c_str()))
273 result = "${CMAKE_INSTALL_PREFIX}/";
275 result += this->Destination;
276 return result;