Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmInstallGenerator.cxx
blob0ee919a38cf8ce144d49e4b4034f9f051da70cf7
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmInstallGenerator.cxx,v $
5 Language: C++
6 Date: $Date: 2009-03-16 14:39:48 $
7 Version: $Revision: 1.17 $
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 cmScriptGenerator("CMAKE_INSTALL_CONFIG_NAME", configurations),
28 Destination(destination? destination:""),
29 Component(component? component:"")
33 //----------------------------------------------------------------------------
34 cmInstallGenerator
35 ::~cmInstallGenerator()
39 //----------------------------------------------------------------------------
40 void cmInstallGenerator
41 ::AddInstallRule(
42 std::ostream& os,
43 int type,
44 std::vector<std::string> const& files,
45 bool optional /* = false */,
46 const char* properties /* = 0 */,
47 const char* permissions_file /* = 0 */,
48 const char* permissions_dir /* = 0 */,
49 const char* rename /* = 0 */,
50 const char* literal_args /* = 0 */,
51 Indent const& indent
54 // Use the FILE command to install the file.
55 std::string stype;
56 switch(type)
58 case cmTarget::INSTALL_DIRECTORY:stype = "DIRECTORY"; break;
59 case cmTarget::INSTALL_PROGRAMS: stype = "PROGRAM"; break;
60 case cmTarget::EXECUTABLE: stype = "EXECUTABLE"; break;
61 case cmTarget::STATIC_LIBRARY: stype = "STATIC_LIBRARY"; break;
62 case cmTarget::SHARED_LIBRARY: stype = "SHARED_LIBRARY"; break;
63 case cmTarget::MODULE_LIBRARY: stype = "MODULE"; break;
64 case cmTarget::INSTALL_FILES:
65 default: stype = "FILE"; break;
67 os << indent;
68 std::string dest = this->GetInstallDestination();
69 os << "FILE(INSTALL DESTINATION \"" << dest << "\" TYPE " << stype.c_str();
70 if(optional)
72 os << " OPTIONAL";
74 if(properties && *properties)
76 os << " PROPERTIES" << properties;
78 if(permissions_file && *permissions_file)
80 os << " PERMISSIONS" << permissions_file;
82 if(permissions_dir && *permissions_dir)
84 os << " DIR_PERMISSIONS" << permissions_dir;
86 if(rename && *rename)
88 os << " RENAME \"" << rename << "\"";
90 os << " FILES";
91 if(files.size() == 1)
93 os << " \"" << files[0] << "\"";
95 else
97 for(std::vector<std::string>::const_iterator fi = files.begin();
98 fi != files.end(); ++fi)
100 os << "\n" << indent << " \"" << *fi << "\"";
102 os << "\n" << indent << " ";
103 if(!(literal_args && *literal_args))
105 os << " ";
108 if(literal_args && *literal_args)
110 os << literal_args;
112 os << ")\n";
115 //----------------------------------------------------------------------------
116 std::string
117 cmInstallGenerator::CreateComponentTest(const char* component)
119 std::string result = "NOT CMAKE_INSTALL_COMPONENT OR "
120 "\"${CMAKE_INSTALL_COMPONENT}\" STREQUAL \"";
121 result += component;
122 result += "\"";
123 return result;
126 //----------------------------------------------------------------------------
127 void cmInstallGenerator::GenerateScript(std::ostream& os)
129 // Track indentation.
130 Indent indent;
132 // Begin this block of installation.
133 std::string component_test =
134 this->CreateComponentTest(this->Component.c_str());
135 os << indent << "IF(" << component_test << ")\n";
137 // Generate the script possibly with per-configuration code.
138 this->GenerateScriptConfigs(os, indent.Next());
140 // End this block of installation.
141 os << indent << "ENDIF(" << component_test << ")\n\n";
144 //----------------------------------------------------------------------------
145 bool cmInstallGenerator::InstallsForConfig(const char* config)
147 return this->GeneratesForConfig(config);
150 //----------------------------------------------------------------------------
151 std::string cmInstallGenerator::GetInstallDestination() const
153 std::string result;
154 if(!this->Destination.empty() &&
155 !cmSystemTools::FileIsFullPath(this->Destination.c_str()))
157 result = "${CMAKE_INSTALL_PREFIX}/";
159 result += this->Destination;
160 return result;