1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #include "cmInstallGenerator.h"
14 #include "cmSystemTools.h"
16 //----------------------------------------------------------------------------
18 ::cmInstallGenerator(const char* destination,
19 std::vector<std::string> const& configurations,
20 const char* component):
21 cmScriptGenerator("CMAKE_INSTALL_CONFIG_NAME", configurations),
22 Destination(destination? destination:""),
23 Component(component? component:"")
27 //----------------------------------------------------------------------------
29 ::~cmInstallGenerator()
33 //----------------------------------------------------------------------------
34 void cmInstallGenerator
38 std::vector<std::string> const& files,
39 bool optional /* = false */,
40 const char* permissions_file /* = 0 */,
41 const char* permissions_dir /* = 0 */,
42 const char* rename /* = 0 */,
43 const char* literal_args /* = 0 */,
47 // Use the FILE command to install the file.
51 case cmInstallType_DIRECTORY: stype = "DIRECTORY"; break;
52 case cmInstallType_PROGRAMS: stype = "PROGRAM"; break;
53 case cmInstallType_EXECUTABLE: stype = "EXECUTABLE"; break;
54 case cmInstallType_STATIC_LIBRARY: stype = "STATIC_LIBRARY"; break;
55 case cmInstallType_SHARED_LIBRARY: stype = "SHARED_LIBRARY"; break;
56 case cmInstallType_MODULE_LIBRARY: stype = "MODULE"; break;
57 case cmInstallType_FILES: stype = "FILE"; break;
60 std::string dest = this->GetInstallDestination();
61 if (cmSystemTools::FileIsFullPath(dest.c_str()))
63 os << "list(APPEND CMAKE_ABSOLUTE_DESTINATION_FILES\n";
64 os << indent << " \"";
65 for(std::vector<std::string>::const_iterator fi = files.begin();
66 fi != files.end(); ++fi)
68 if (fi!=files.begin())
73 if (rename && *rename)
79 os << cmSystemTools::GetFilenameName(*fi);
83 os << indent << "IF (CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)\n";
84 os << indent << indent << "message(WARNING \"ABSOLUTE path INSTALL "
85 << "DESTINATION : ${CMAKE_ABSOLUTE_DESTINATION_FILES}\")\n";
86 os << indent << "ENDIF (CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)\n";
88 os << indent << "IF (CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)\n";
89 os << indent << indent << "message(FATAL_ERROR \"ABSOLUTE path INSTALL "
90 << "DESTINATION forbidden (by caller): "
91 << "${CMAKE_ABSOLUTE_DESTINATION_FILES}\")\n";
92 os << indent << "ENDIF (CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)\n";
94 os << "FILE(INSTALL DESTINATION \"" << dest << "\" TYPE " << stype.c_str();
99 if(permissions_file && *permissions_file)
101 os << " PERMISSIONS" << permissions_file;
103 if(permissions_dir && *permissions_dir)
105 os << " DIR_PERMISSIONS" << permissions_dir;
107 if(rename && *rename)
109 os << " RENAME \"" << rename << "\"";
112 if(files.size() == 1)
114 os << " \"" << files[0] << "\"";
118 for(std::vector<std::string>::const_iterator fi = files.begin();
119 fi != files.end(); ++fi)
121 os << "\n" << indent << " \"" << *fi << "\"";
123 os << "\n" << indent << " ";
124 if(!(literal_args && *literal_args))
129 if(literal_args && *literal_args)
136 //----------------------------------------------------------------------------
138 cmInstallGenerator::CreateComponentTest(const char* component)
140 std::string result = "NOT CMAKE_INSTALL_COMPONENT OR "
141 "\"${CMAKE_INSTALL_COMPONENT}\" STREQUAL \"";
147 //----------------------------------------------------------------------------
148 void cmInstallGenerator::GenerateScript(std::ostream& os)
150 // Track indentation.
153 // Begin this block of installation.
154 std::string component_test =
155 this->CreateComponentTest(this->Component.c_str());
156 os << indent << "IF(" << component_test << ")\n";
158 // Generate the script possibly with per-configuration code.
159 this->GenerateScriptConfigs(os, indent.Next());
161 // End this block of installation.
162 os << indent << "ENDIF(" << component_test << ")\n\n";
165 //----------------------------------------------------------------------------
166 bool cmInstallGenerator::InstallsForConfig(const char* config)
168 return this->GeneratesForConfig(config);
171 //----------------------------------------------------------------------------
172 std::string cmInstallGenerator::GetInstallDestination() const
175 if(!this->Destination.empty() &&
176 !cmSystemTools::FileIsFullPath(this->Destination.c_str()))
178 result = "${CMAKE_INSTALL_PREFIX}/";
180 result += this->Destination;