1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmInstallGenerator.cxx,v $
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"
22 //----------------------------------------------------------------------------
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
:""),
35 //----------------------------------------------------------------------------
37 ::~cmInstallGenerator()
41 //----------------------------------------------------------------------------
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
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.
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;
83 std::string dest
= this->GetInstallDestination();
84 os
<< "FILE(INSTALL DESTINATION \"" << dest
<< "\" TYPE " << stype
.c_str();
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
<< "\"";
106 if(files
.size() == 1)
108 os
<< " \"" << files
[0] << "\"";
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
))
123 if(literal_args
&& *literal_args
)
130 //----------------------------------------------------------------------------
131 static void cmInstallGeneratorEncodeConfig(const char* config
,
134 for(const char* c
= config
; *c
; ++c
)
136 if(*c
>= 'a' && *c
<= 'z')
139 result
+= *c
+ ('A' - 'a');
143 else if(*c
>= 'A' && *c
<= 'Z')
147 result
+= *c
+ ('a' - 'A');
157 //----------------------------------------------------------------------------
159 cmInstallGenerator::CreateConfigTest(const char* config
)
161 std::string result
= "\"${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^(";
162 if(config
&& *config
)
164 cmInstallGeneratorEncodeConfig(config
, result
);
170 //----------------------------------------------------------------------------
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
)
181 cmInstallGeneratorEncodeConfig(ci
->c_str(), result
);
187 //----------------------------------------------------------------------------
189 cmInstallGenerator::CreateComponentTest(const char* component
)
191 std::string result
= "NOT CMAKE_INSTALL_COMPONENT OR "
192 "\"${CMAKE_INSTALL_COMPONENT}\" MATCHES \"^(";
198 //----------------------------------------------------------------------------
199 void cmInstallGenerator::GenerateScript(std::ostream
& os
)
201 // Track indentation.
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 //----------------------------------------------------------------------------
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
);
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())
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
)
266 //----------------------------------------------------------------------------
267 std::string
cmInstallGenerator::GetInstallDestination() const
270 if(!this->Destination
.empty() &&
271 !cmSystemTools::FileIsFullPath(this->Destination
.c_str()))
273 result
= "${CMAKE_INSTALL_PREFIX}/";
275 result
+= this->Destination
;