2016-09-27 19:01:08 +00: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 20:25:27 +00:00
|
|
|
#include "cmInstallGenerator.h"
|
|
|
|
|
2014-06-24 15:18:43 +00:00
|
|
|
#include "cmMakefile.h"
|
2006-02-19 20:25:27 +00:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
2016-09-01 18:59:28 +00:00
|
|
|
#include <ostream>
|
|
|
|
|
2016-05-16 14:34:04 +00: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 20:25:27 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
cmInstallGenerator::~cmInstallGenerator()
|
2006-02-19 20:25:27 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00: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 20:25:27 +00:00
|
|
|
{
|
2006-02-19 21:12:29 +00:00
|
|
|
// Use the FILE command to install the file.
|
2006-02-19 20:25:27 +00:00
|
|
|
std::string stype;
|
2016-05-16 14:34:04 +00: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 15:02:52 +00:00
|
|
|
os << indent;
|
2016-05-16 14:34:04 +00: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-14 21:29:42 +00:00
|
|
|
|
2016-05-16 14:34:04 +00: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 16:52:19 +00:00
|
|
|
std::string absDest = this->ConvertToAbsoluteDestination(dest);
|
|
|
|
os << "file(INSTALL DESTINATION \"" << absDest << "\" TYPE " << stype;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (optional) {
|
2006-02-20 00:29:30 +00:00
|
|
|
os << " OPTIONAL";
|
2016-05-16 14:34:04 +00: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 18:48:54 +00:00
|
|
|
os << " PERMISSIONS" << permissions_file;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (permissions_dir && *permissions_dir) {
|
2006-08-17 18:48:54 +00:00
|
|
|
os << " DIR_PERMISSIONS" << permissions_dir;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (rename && *rename) {
|
2006-03-03 23:44:32 +00:00
|
|
|
os << " RENAME \"" << rename << "\"";
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-28 20:11:18 +00:00
|
|
|
os << " FILES";
|
2016-05-16 14:34:04 +00:00
|
|
|
if (files.size() == 1) {
|
2007-06-28 20:11:18 +00:00
|
|
|
os << " \"" << files[0] << "\"";
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
|
|
|
for (std::vector<std::string>::const_iterator fi = files.begin();
|
|
|
|
fi != files.end(); ++fi) {
|
2007-07-02 15:02:52 +00:00
|
|
|
os << "\n" << indent << " \"" << *fi << "\"";
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-07-02 15:02:52 +00:00
|
|
|
os << "\n" << indent << " ";
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!(literal_args && *literal_args)) {
|
2007-06-28 20:11:18 +00:00
|
|
|
os << " ";
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (literal_args && *literal_args) {
|
2006-08-21 20:55:03 +00:00
|
|
|
os << literal_args;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2006-08-21 20:55:03 +00:00
|
|
|
os << ")\n";
|
2006-02-19 20:25:27 +00:00
|
|
|
}
|
2007-07-02 18:56:57 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string cmInstallGenerator::CreateComponentTest(const char* component,
|
|
|
|
bool exclude_from_all)
|
2007-07-02 18:56:57 +00:00
|
|
|
{
|
2016-02-01 10:01:39 +00:00
|
|
|
std::string result = "\"${CMAKE_INSTALL_COMPONENT}\" STREQUAL \"";
|
2007-07-02 18:56:57 +00:00
|
|
|
result += component;
|
2008-12-16 14:20:51 +00:00
|
|
|
result += "\"";
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!exclude_from_all) {
|
2016-02-01 10:01:39 +00:00
|
|
|
result += " OR NOT CMAKE_INSTALL_COMPONENT";
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-07-02 18:56:57 +00: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 14:34:04 +00:00
|
|
|
this->CreateComponentTest(this->Component.c_str(), this->ExcludeFromAll);
|
2013-08-22 09:30:19 +00:00
|
|
|
os << indent << "if(" << component_test << ")\n";
|
2007-07-02 18:56:57 +00:00
|
|
|
|
|
|
|
// Generate the script possibly with per-configuration code.
|
|
|
|
this->GenerateScriptConfigs(os, indent.Next());
|
|
|
|
|
|
|
|
// End this block of installation.
|
2013-08-22 09:30:19 +00:00
|
|
|
os << indent << "endif()\n\n";
|
2007-07-02 18:56:57 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 03:48:34 +00:00
|
|
|
bool cmInstallGenerator::InstallsForConfig(const std::string& config)
|
2008-01-28 13:38:36 +00:00
|
|
|
{
|
2009-03-16 14:39:56 +00:00
|
|
|
return this->GeneratesForConfig(config);
|
2008-01-28 13:38:36 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string cmInstallGenerator::ConvertToAbsoluteDestination(
|
|
|
|
std::string const& dest) const
|
2008-01-28 13:38:36 +00:00
|
|
|
{
|
|
|
|
std::string result;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!dest.empty() && !cmSystemTools::FileIsFullPath(dest.c_str())) {
|
2008-01-28 13:38:36 +00:00
|
|
|
result = "${CMAKE_INSTALL_PREFIX}/";
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-02-11 16:48:02 +00:00
|
|
|
result += dest;
|
2008-01-28 13:38:36 +00:00
|
|
|
return result;
|
|
|
|
}
|
2014-06-24 15:18:43 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
cmInstallGenerator::MessageLevel cmInstallGenerator::SelectMessageLevel(
|
|
|
|
cmMakefile* mf, bool never)
|
2014-06-24 15:18:43 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (never) {
|
2014-06-24 15:40:26 +00:00
|
|
|
return MessageNever;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-06-24 15:18:43 +00:00
|
|
|
std::string m = mf->GetSafeDefinition("CMAKE_INSTALL_MESSAGE");
|
2016-05-16 14:34:04 +00:00
|
|
|
if (m == "ALWAYS") {
|
2014-06-24 15:18:43 +00:00
|
|
|
return MessageAlways;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (m == "LAZY") {
|
2014-06-24 15:18:43 +00:00
|
|
|
return MessageLazy;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (m == "NEVER") {
|
2014-06-24 15:18:43 +00:00
|
|
|
return MessageNever;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-06-24 15:18:43 +00:00
|
|
|
return MessageDefault;
|
|
|
|
}
|