2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2006-02-19 23:25:27 +03:00
|
|
|
#include "cmInstallGenerator.h"
|
|
|
|
|
2014-06-24 19:18:43 +04:00
|
|
|
#include "cmMakefile.h"
|
2006-02-19 23:25:27 +03:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
2016-09-01 21:59:28 +03:00
|
|
|
#include <ostream>
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmInstallGenerator::cmInstallGenerator(
|
|
|
|
const char* destination, std::vector<std::string> const& configurations,
|
|
|
|
const char* component, MessageLevel message, bool exclude_from_all)
|
|
|
|
: cmScriptGenerator("CMAKE_INSTALL_CONFIG_NAME", configurations)
|
|
|
|
, Destination(destination ? destination : "")
|
|
|
|
, Component(component ? component : "")
|
|
|
|
, Message(message)
|
|
|
|
, ExcludeFromAll(exclude_from_all)
|
2006-02-19 23:25:27 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmInstallGenerator::~cmInstallGenerator()
|
2006-02-19 23:25:27 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmInstallGenerator::AddInstallRule(
|
|
|
|
std::ostream& os, std::string const& dest, cmInstallType type,
|
|
|
|
std::vector<std::string> const& files, bool optional /* = false */,
|
|
|
|
const char* permissions_file /* = 0 */,
|
|
|
|
const char* permissions_dir /* = 0 */, const char* rename /* = 0 */,
|
|
|
|
const char* literal_args /* = 0 */, Indent const& indent)
|
2006-02-19 23:25:27 +03:00
|
|
|
{
|
2006-02-20 00:12:29 +03:00
|
|
|
// Use the FILE command to install the file.
|
2006-02-19 23:25:27 +03:00
|
|
|
std::string stype;
|
2016-05-16 17:34:04 +03:00
|
|
|
switch (type) {
|
|
|
|
case cmInstallType_DIRECTORY:
|
|
|
|
stype = "DIRECTORY";
|
|
|
|
break;
|
|
|
|
case cmInstallType_PROGRAMS:
|
|
|
|
stype = "PROGRAM";
|
|
|
|
break;
|
|
|
|
case cmInstallType_EXECUTABLE:
|
|
|
|
stype = "EXECUTABLE";
|
|
|
|
break;
|
|
|
|
case cmInstallType_STATIC_LIBRARY:
|
|
|
|
stype = "STATIC_LIBRARY";
|
|
|
|
break;
|
|
|
|
case cmInstallType_SHARED_LIBRARY:
|
|
|
|
stype = "SHARED_LIBRARY";
|
|
|
|
break;
|
|
|
|
case cmInstallType_MODULE_LIBRARY:
|
|
|
|
stype = "MODULE";
|
|
|
|
break;
|
|
|
|
case cmInstallType_FILES:
|
|
|
|
stype = "FILE";
|
|
|
|
break;
|
|
|
|
}
|
2007-07-02 19:02:52 +04:00
|
|
|
os << indent;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileIsFullPath(dest.c_str())) {
|
|
|
|
os << "list(APPEND CMAKE_ABSOLUTE_DESTINATION_FILES\n";
|
|
|
|
os << indent << " \"";
|
|
|
|
for (std::vector<std::string>::const_iterator fi = files.begin();
|
|
|
|
fi != files.end(); ++fi) {
|
|
|
|
if (fi != files.begin()) {
|
|
|
|
os << ";";
|
|
|
|
}
|
|
|
|
os << dest << "/";
|
|
|
|
if (rename && *rename) {
|
|
|
|
os << rename;
|
|
|
|
} else {
|
|
|
|
os << cmSystemTools::GetFilenameName(*fi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
os << "\")\n";
|
|
|
|
os << indent << "if(CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)\n";
|
|
|
|
os << indent << indent << "message(WARNING \"ABSOLUTE path INSTALL "
|
|
|
|
<< "DESTINATION : ${CMAKE_ABSOLUTE_DESTINATION_FILES}\")\n";
|
|
|
|
os << indent << "endif()\n";
|
2012-05-15 01:29:42 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
os << indent << "if(CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)\n";
|
|
|
|
os << indent << indent << "message(FATAL_ERROR \"ABSOLUTE path INSTALL "
|
|
|
|
<< "DESTINATION forbidden (by caller): "
|
|
|
|
<< "${CMAKE_ABSOLUTE_DESTINATION_FILES}\")\n";
|
|
|
|
os << indent << "endif()\n";
|
|
|
|
}
|
2015-02-11 19:52:19 +03:00
|
|
|
std::string absDest = this->ConvertToAbsoluteDestination(dest);
|
|
|
|
os << "file(INSTALL DESTINATION \"" << absDest << "\" TYPE " << stype;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (optional) {
|
2006-02-20 03:29:30 +03:00
|
|
|
os << " OPTIONAL";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
switch (this->Message) {
|
|
|
|
case MessageDefault:
|
|
|
|
break;
|
|
|
|
case MessageAlways:
|
|
|
|
os << " MESSAGE_ALWAYS";
|
|
|
|
break;
|
|
|
|
case MessageLazy:
|
|
|
|
os << " MESSAGE_LAZY";
|
|
|
|
break;
|
|
|
|
case MessageNever:
|
|
|
|
os << " MESSAGE_NEVER";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (permissions_file && *permissions_file) {
|
2006-08-17 22:48:54 +04:00
|
|
|
os << " PERMISSIONS" << permissions_file;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (permissions_dir && *permissions_dir) {
|
2006-08-17 22:48:54 +04:00
|
|
|
os << " DIR_PERMISSIONS" << permissions_dir;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (rename && *rename) {
|
2006-03-04 02:44:32 +03:00
|
|
|
os << " RENAME \"" << rename << "\"";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-29 00:11:18 +04:00
|
|
|
os << " FILES";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (files.size() == 1) {
|
2007-06-29 00:11:18 +04:00
|
|
|
os << " \"" << files[0] << "\"";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
|
|
|
for (std::vector<std::string>::const_iterator fi = files.begin();
|
|
|
|
fi != files.end(); ++fi) {
|
2007-07-02 19:02:52 +04:00
|
|
|
os << "\n" << indent << " \"" << *fi << "\"";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-07-02 19:02:52 +04:00
|
|
|
os << "\n" << indent << " ";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!(literal_args && *literal_args)) {
|
2007-06-29 00:11:18 +04:00
|
|
|
os << " ";
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (literal_args && *literal_args) {
|
2006-08-22 00:55:03 +04:00
|
|
|
os << literal_args;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-08-22 00:55:03 +04:00
|
|
|
os << ")\n";
|
2006-02-19 23:25:27 +03:00
|
|
|
}
|
2007-07-02 22:56:57 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmInstallGenerator::CreateComponentTest(const char* component,
|
|
|
|
bool exclude_from_all)
|
2007-07-02 22:56:57 +04:00
|
|
|
{
|
2016-02-01 13:01:39 +03:00
|
|
|
std::string result = "\"${CMAKE_INSTALL_COMPONENT}\" STREQUAL \"";
|
2007-07-02 22:56:57 +04:00
|
|
|
result += component;
|
2008-12-16 17:20:51 +03:00
|
|
|
result += "\"";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!exclude_from_all) {
|
2016-02-01 13:01:39 +03:00
|
|
|
result += " OR NOT CMAKE_INSTALL_COMPONENT";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-07-02 22:56:57 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmInstallGenerator::GenerateScript(std::ostream& os)
|
|
|
|
{
|
|
|
|
// Track indentation.
|
|
|
|
Indent indent;
|
|
|
|
|
|
|
|
// Begin this block of installation.
|
|
|
|
std::string component_test =
|
2016-05-16 17:34:04 +03:00
|
|
|
this->CreateComponentTest(this->Component.c_str(), this->ExcludeFromAll);
|
2013-08-22 13:30:19 +04:00
|
|
|
os << indent << "if(" << component_test << ")\n";
|
2007-07-02 22:56:57 +04:00
|
|
|
|
|
|
|
// Generate the script possibly with per-configuration code.
|
|
|
|
this->GenerateScriptConfigs(os, indent.Next());
|
|
|
|
|
|
|
|
// End this block of installation.
|
2013-08-22 13:30:19 +04:00
|
|
|
os << indent << "endif()\n\n";
|
2007-07-02 22:56:57 +04:00
|
|
|
}
|
|
|
|
|
2014-02-10 07:48:34 +04:00
|
|
|
bool cmInstallGenerator::InstallsForConfig(const std::string& config)
|
2008-01-28 16:38:36 +03:00
|
|
|
{
|
2009-03-16 17:39:56 +03:00
|
|
|
return this->GeneratesForConfig(config);
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmInstallGenerator::ConvertToAbsoluteDestination(
|
|
|
|
std::string const& dest) const
|
2008-01-28 16:38:36 +03:00
|
|
|
{
|
|
|
|
std::string result;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!dest.empty() && !cmSystemTools::FileIsFullPath(dest.c_str())) {
|
2008-01-28 16:38:36 +03:00
|
|
|
result = "${CMAKE_INSTALL_PREFIX}/";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-02-11 19:48:02 +03:00
|
|
|
result += dest;
|
2008-01-28 16:38:36 +03:00
|
|
|
return result;
|
|
|
|
}
|
2014-06-24 19:18:43 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmInstallGenerator::MessageLevel cmInstallGenerator::SelectMessageLevel(
|
|
|
|
cmMakefile* mf, bool never)
|
2014-06-24 19:18:43 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (never) {
|
2014-06-24 19:40:26 +04:00
|
|
|
return MessageNever;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-06-24 19:18:43 +04:00
|
|
|
std::string m = mf->GetSafeDefinition("CMAKE_INSTALL_MESSAGE");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (m == "ALWAYS") {
|
2014-06-24 19:18:43 +04:00
|
|
|
return MessageAlways;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (m == "LAZY") {
|
2014-06-24 19:18:43 +04:00
|
|
|
return MessageLazy;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (m == "NEVER") {
|
2014-06-24 19:18:43 +04:00
|
|
|
return MessageNever;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-06-24 19:18:43 +04:00
|
|
|
return MessageDefault;
|
|
|
|
}
|