2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2006-02-19 23:25:27 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2006-02-19 23:25:27 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2006-02-19 23:25:27 +03:00
|
|
|
#include "cmInstallGenerator.h"
|
|
|
|
|
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
cmInstallGenerator
|
2007-07-02 22:56:57 +04:00
|
|
|
::cmInstallGenerator(const char* destination,
|
|
|
|
std::vector<std::string> const& configurations,
|
|
|
|
const char* component):
|
2009-03-16 17:39:56 +03:00
|
|
|
cmScriptGenerator("CMAKE_INSTALL_CONFIG_NAME", configurations),
|
2007-07-02 22:56:57 +04:00
|
|
|
Destination(destination? destination:""),
|
2009-03-16 17:39:56 +03:00
|
|
|
Component(component? component:"")
|
2006-02-19 23:25:27 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
cmInstallGenerator
|
|
|
|
::~cmInstallGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2006-05-11 23:50:11 +04:00
|
|
|
void cmInstallGenerator
|
|
|
|
::AddInstallRule(
|
|
|
|
std::ostream& os,
|
2012-02-27 20:26:38 +04:00
|
|
|
cmInstallType type,
|
2007-06-29 00:11:18 +04:00
|
|
|
std::vector<std::string> const& files,
|
2006-05-11 23:50:11 +04:00
|
|
|
bool optional /* = false */,
|
2006-08-17 22:48:54 +04:00
|
|
|
const char* permissions_file /* = 0 */,
|
|
|
|
const char* permissions_dir /* = 0 */,
|
2006-08-22 00:55:03 +04:00
|
|
|
const char* rename /* = 0 */,
|
2007-07-02 19:02:52 +04:00
|
|
|
const char* literal_args /* = 0 */,
|
2009-03-16 17:39:56 +03:00
|
|
|
Indent const& indent
|
2006-05-11 23:50:11 +04:00
|
|
|
)
|
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;
|
|
|
|
switch(type)
|
|
|
|
{
|
2012-02-27 20:26:38 +04:00
|
|
|
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;
|
2006-02-19 23:25:27 +03:00
|
|
|
}
|
2007-07-02 19:02:52 +04:00
|
|
|
os << indent;
|
2008-01-28 16:38:36 +03:00
|
|
|
std::string dest = this->GetInstallDestination();
|
2010-08-23 19:38:33 +04:00
|
|
|
if (cmSystemTools::FileIsFullPath(dest.c_str()))
|
|
|
|
{
|
2012-05-20 19:28:54 +04:00
|
|
|
os << "list(APPEND CMAKE_ABSOLUTE_DESTINATION_FILES\n";
|
2010-08-23 19:38:33 +04:00
|
|
|
os << indent << " \"";
|
|
|
|
for(std::vector<std::string>::const_iterator fi = files.begin();
|
|
|
|
fi != files.end(); ++fi)
|
|
|
|
{
|
2010-09-20 21:12:54 +04:00
|
|
|
if (fi!=files.begin())
|
|
|
|
{
|
|
|
|
os << ";";
|
|
|
|
}
|
|
|
|
os << dest << "/";
|
2010-08-23 19:38:33 +04:00
|
|
|
if (rename && *rename)
|
|
|
|
{
|
|
|
|
os << rename;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
os << cmSystemTools::GetFilenameName(*fi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
os << "\")\n";
|
2013-08-22 13:30:19 +04:00
|
|
|
os << indent << "if(CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)\n";
|
2012-05-15 01:29:42 +04:00
|
|
|
os << indent << indent << "message(WARNING \"ABSOLUTE path INSTALL "
|
2012-05-20 19:28:54 +04:00
|
|
|
<< "DESTINATION : ${CMAKE_ABSOLUTE_DESTINATION_FILES}\")\n";
|
2013-08-22 13:30:19 +04:00
|
|
|
os << indent << "endif()\n";
|
2012-05-15 01:29:42 +04:00
|
|
|
|
2013-08-22 13:30:19 +04:00
|
|
|
os << indent << "if(CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)\n";
|
2012-05-15 01:29:42 +04:00
|
|
|
os << indent << indent << "message(FATAL_ERROR \"ABSOLUTE path INSTALL "
|
2012-05-20 19:28:54 +04:00
|
|
|
<< "DESTINATION forbidden (by caller): "
|
|
|
|
<< "${CMAKE_ABSOLUTE_DESTINATION_FILES}\")\n";
|
2013-08-22 13:30:19 +04:00
|
|
|
os << indent << "endif()\n";
|
2010-08-23 19:38:33 +04:00
|
|
|
}
|
2013-08-22 13:30:19 +04:00
|
|
|
os << "file(INSTALL DESTINATION \"" << dest << "\" TYPE " << stype.c_str();
|
2006-02-20 03:29:30 +03:00
|
|
|
if(optional)
|
|
|
|
{
|
|
|
|
os << " OPTIONAL";
|
|
|
|
}
|
2006-08-17 22:48:54 +04:00
|
|
|
if(permissions_file && *permissions_file)
|
2006-03-04 02:44:32 +03:00
|
|
|
{
|
2006-08-17 22:48:54 +04:00
|
|
|
os << " PERMISSIONS" << permissions_file;
|
|
|
|
}
|
|
|
|
if(permissions_dir && *permissions_dir)
|
|
|
|
{
|
|
|
|
os << " DIR_PERMISSIONS" << permissions_dir;
|
2006-03-04 02:44:32 +03:00
|
|
|
}
|
|
|
|
if(rename && *rename)
|
|
|
|
{
|
|
|
|
os << " RENAME \"" << rename << "\"";
|
|
|
|
}
|
2007-06-29 00:11:18 +04:00
|
|
|
os << " FILES";
|
|
|
|
if(files.size() == 1)
|
|
|
|
{
|
|
|
|
os << " \"" << files[0] << "\"";
|
|
|
|
}
|
|
|
|
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 << "\"";
|
2007-06-29 00:11:18 +04:00
|
|
|
}
|
2007-07-02 19:02:52 +04:00
|
|
|
os << "\n" << indent << " ";
|
2007-06-29 00:11:18 +04:00
|
|
|
if(!(literal_args && *literal_args))
|
|
|
|
{
|
|
|
|
os << " ";
|
|
|
|
}
|
|
|
|
}
|
2006-08-22 00:55:03 +04:00
|
|
|
if(literal_args && *literal_args)
|
|
|
|
{
|
|
|
|
os << literal_args;
|
|
|
|
}
|
|
|
|
os << ")\n";
|
2006-02-19 23:25:27 +03:00
|
|
|
}
|
2007-07-02 22:56:57 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
std::string
|
|
|
|
cmInstallGenerator::CreateComponentTest(const char* component)
|
|
|
|
{
|
|
|
|
std::string result = "NOT CMAKE_INSTALL_COMPONENT OR "
|
2008-12-16 17:20:51 +03:00
|
|
|
"\"${CMAKE_INSTALL_COMPONENT}\" STREQUAL \"";
|
2007-07-02 22:56:57 +04:00
|
|
|
result += component;
|
2008-12-16 17:20:51 +03:00
|
|
|
result += "\"";
|
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 =
|
|
|
|
this->CreateComponentTest(this->Component.c_str());
|
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
|
|
|
}
|
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmInstallGenerator::InstallsForConfig(const char* config)
|
|
|
|
{
|
2009-03-16 17:39:56 +03:00
|
|
|
return this->GeneratesForConfig(config);
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
std::string cmInstallGenerator::GetInstallDestination() const
|
|
|
|
{
|
|
|
|
std::string result;
|
|
|
|
if(!this->Destination.empty() &&
|
|
|
|
!cmSystemTools::FileIsFullPath(this->Destination.c_str()))
|
|
|
|
{
|
|
|
|
result = "${CMAKE_INSTALL_PREFIX}/";
|
|
|
|
}
|
|
|
|
result += this->Destination;
|
|
|
|
return result;
|
|
|
|
}
|