2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2007-06-19 21:10:21 +04: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.
|
2007-06-19 21:10:21 +04: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.
|
|
|
|
============================================================================*/
|
2008-01-28 16:38:36 +03:00
|
|
|
#include "cmInstallExportGenerator.h"
|
2007-06-19 21:10:21 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "cmGeneratedFileStream.h"
|
2008-01-28 16:38:36 +03:00
|
|
|
#include "cmGlobalGenerator.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmInstallTargetGenerator.h"
|
|
|
|
#include "cmLocalGenerator.h"
|
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmake.h"
|
2007-06-19 21:10:21 +04:00
|
|
|
|
2007-08-28 00:04:57 +04:00
|
|
|
#include "cmInstallFilesGenerator.h"
|
2007-06-19 21:10:21 +04:00
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
#include "cmExportInstallFileGenerator.h"
|
2012-02-27 10:09:40 +04:00
|
|
|
#include "cmExportSet.h"
|
2008-01-28 16:38:36 +03:00
|
|
|
|
2007-07-02 22:56:57 +04:00
|
|
|
cmInstallExportGenerator::cmInstallExportGenerator(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmExportSet* exportSet, const char* destination,
|
|
|
|
const char* file_permissions, std::vector<std::string> const& configurations,
|
|
|
|
const char* component, MessageLevel message, bool exclude_from_all,
|
|
|
|
const char* filename, const char* name_space, bool exportOld)
|
|
|
|
: cmInstallGenerator(destination, configurations, component, message,
|
|
|
|
exclude_from_all)
|
|
|
|
, ExportSet(exportSet)
|
|
|
|
, FilePermissions(file_permissions)
|
|
|
|
, FileName(filename)
|
|
|
|
, Namespace(name_space)
|
|
|
|
, ExportOld(exportOld)
|
2016-06-27 23:44:16 +03:00
|
|
|
, LocalGenerator(CM_NULLPTR)
|
2008-01-28 16:38:36 +03:00
|
|
|
{
|
|
|
|
this->EFGen = new cmExportInstallFileGenerator(this);
|
2012-09-15 23:04:48 +04:00
|
|
|
exportSet->AddInstallation(this);
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cmInstallExportGenerator::~cmInstallExportGenerator()
|
2007-06-19 21:10:21 +04:00
|
|
|
{
|
2008-01-28 16:38:36 +03:00
|
|
|
delete this->EFGen;
|
2007-06-19 21:10:21 +04:00
|
|
|
}
|
|
|
|
|
2015-08-06 00:05:22 +03:00
|
|
|
void cmInstallExportGenerator::Compute(cmLocalGenerator* lg)
|
|
|
|
{
|
|
|
|
this->LocalGenerator = lg;
|
2015-10-17 14:31:33 +03:00
|
|
|
this->ExportSet->Compute(lg);
|
2015-08-06 00:05:22 +03:00
|
|
|
}
|
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
void cmInstallExportGenerator::ComputeTempDir()
|
2007-06-19 21:10:21 +04:00
|
|
|
{
|
2008-01-28 16:38:36 +03:00
|
|
|
// Choose a temporary directory in which to generate the import
|
|
|
|
// files to be installed.
|
2016-05-16 17:34:04 +03:00
|
|
|
this->TempDir = this->LocalGenerator->GetCurrentBinaryDirectory();
|
2008-01-28 16:38:36 +03:00
|
|
|
this->TempDir += cmake::GetCMakeFilesDirectory();
|
|
|
|
this->TempDir += "/Export";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Destination.empty()) {
|
2008-01-28 16:38:36 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2008-01-28 16:38:36 +03:00
|
|
|
this->TempDir += "/";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-19 21:10:21 +04:00
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
// Enforce a maximum length.
|
|
|
|
bool useMD5 = false;
|
|
|
|
#if defined(_WIN32) || defined(__CYGWIN__)
|
|
|
|
std::string::size_type const max_total_len = 250;
|
|
|
|
#else
|
|
|
|
std::string::size_type const max_total_len = 1000;
|
|
|
|
#endif
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->TempDir.size() < max_total_len) {
|
2008-01-28 16:38:36 +03:00
|
|
|
// Keep the total path length below the limit.
|
|
|
|
std::string::size_type max_len = max_total_len - this->TempDir.size();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Destination.size() > max_len) {
|
2008-01-28 16:38:36 +03:00
|
|
|
useMD5 = true;
|
2007-06-19 21:10:21 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2008-01-28 16:38:36 +03:00
|
|
|
useMD5 = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (useMD5) {
|
2008-01-28 16:38:36 +03:00
|
|
|
// Replace the destination path with a hash to keep it short.
|
2016-05-16 17:34:04 +03:00
|
|
|
this->TempDir += cmSystemTools::ComputeStringMD5(this->Destination);
|
|
|
|
} else {
|
2008-01-28 16:38:36 +03:00
|
|
|
std::string dest = this->Destination;
|
|
|
|
// Avoid unix full paths.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (dest[0] == '/') {
|
2008-01-28 16:38:36 +03:00
|
|
|
dest[0] = '_';
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-28 16:38:36 +03:00
|
|
|
// Avoid windows full paths by removing colons.
|
Use std::replace for replacing chars in strings.
Find uses of `cmSystemTools::ReplaceString` where both `replace` and
`with` are string literals with a size of one.
Automate with:
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\2', '\3');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\\\\\\\\\");|std::replace(\1.begin(), \1.end(), '\2', '\\\\\\\\');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\\\\\\\\\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\\\\\\\\', '\2');|g"
2016-05-24 23:58:11 +03:00
|
|
|
std::replace(dest.begin(), dest.end(), ':', '_');
|
2008-01-28 16:38:36 +03:00
|
|
|
// Avoid relative paths that go up the tree.
|
|
|
|
cmSystemTools::ReplaceString(dest, "../", "__/");
|
|
|
|
// Avoid spaces.
|
Use std::replace for replacing chars in strings.
Find uses of `cmSystemTools::ReplaceString` where both `replace` and
`with` are string literals with a size of one.
Automate with:
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\2', '\3');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\\\\\\\\\");|std::replace(\1.begin(), \1.end(), '\2', '\\\\\\\\');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\\\\\\\\\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\\\\\\\\', '\2');|g"
2016-05-24 23:58:11 +03:00
|
|
|
std::replace(dest.begin(), dest.end(), ' ', '_');
|
2008-01-28 16:38:36 +03:00
|
|
|
this->TempDir += dest;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-08-28 00:04:57 +04:00
|
|
|
}
|
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
void cmInstallExportGenerator::GenerateScript(std::ostream& os)
|
2007-06-19 21:10:21 +04:00
|
|
|
{
|
2008-01-28 16:38:36 +03:00
|
|
|
// Skip empty sets.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (ExportSet->GetTargetExports()->empty()) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2016-05-16 17:34:04 +03:00
|
|
|
e << "INSTALL(EXPORT) given unknown export \"" << ExportSet->GetName()
|
|
|
|
<< "\"";
|
2008-01-28 16:38:36 +03:00
|
|
|
cmSystemTools::Error(e.str().c_str());
|
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-19 21:10:21 +04:00
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
// Create the temporary directory in which to store the files.
|
|
|
|
this->ComputeTempDir();
|
|
|
|
cmSystemTools::MakeDirectory(this->TempDir.c_str());
|
|
|
|
|
|
|
|
// Construct a temporary location for the file.
|
|
|
|
this->MainImportFile = this->TempDir;
|
|
|
|
this->MainImportFile += "/";
|
|
|
|
this->MainImportFile += this->FileName;
|
|
|
|
|
|
|
|
// Generate the import file for this export set.
|
|
|
|
this->EFGen->SetExportFile(this->MainImportFile.c_str());
|
2014-03-11 03:04:11 +04:00
|
|
|
this->EFGen->SetNamespace(this->Namespace);
|
2013-06-04 18:47:57 +04:00
|
|
|
this->EFGen->SetExportOld(this->ExportOld);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->ConfigurationTypes->empty()) {
|
|
|
|
if (!this->ConfigurationName.empty()) {
|
2008-01-28 16:38:36 +03:00
|
|
|
this->EFGen->AddConfiguration(this->ConfigurationName);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2008-01-28 16:38:36 +03:00
|
|
|
this->EFGen->AddConfiguration("");
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
|
|
|
for (std::vector<std::string>::const_iterator ci =
|
|
|
|
this->ConfigurationTypes->begin();
|
|
|
|
ci != this->ConfigurationTypes->end(); ++ci) {
|
2014-03-11 03:04:11 +04:00
|
|
|
this->EFGen->AddConfiguration(*ci);
|
2007-06-19 21:10:21 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-28 16:38:36 +03:00
|
|
|
this->EFGen->GenerateImportFile();
|
2007-06-19 21:10:21 +04:00
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
// Perform the main install script generation.
|
|
|
|
this->cmInstallGenerator::GenerateScript(os);
|
2007-06-19 21:10:21 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmInstallExportGenerator::GenerateScriptConfigs(std::ostream& os,
|
|
|
|
Indent const& indent)
|
2007-06-19 21:10:21 +04:00
|
|
|
{
|
2008-01-28 16:38:36 +03:00
|
|
|
// Create the main install rules first.
|
|
|
|
this->cmInstallGenerator::GenerateScriptConfigs(os, indent);
|
|
|
|
|
|
|
|
// Now create a configuration-specific install rule for the import
|
|
|
|
// file of each configuration.
|
|
|
|
std::vector<std::string> files;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::map<std::string, std::string>::const_iterator i =
|
|
|
|
this->EFGen->GetConfigImportFiles().begin();
|
|
|
|
i != this->EFGen->GetConfigImportFiles().end(); ++i) {
|
2008-01-28 16:38:36 +03:00
|
|
|
files.push_back(i->second);
|
2014-03-11 03:04:11 +04:00
|
|
|
std::string config_test = this->CreateConfigTest(i->first);
|
2013-08-22 13:30:19 +04:00
|
|
|
os << indent << "if(" << config_test << ")\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
this->AddInstallRule(os, this->Destination, cmInstallType_FILES, files,
|
2016-06-27 23:44:16 +03:00
|
|
|
false, this->FilePermissions.c_str(), CM_NULLPTR,
|
|
|
|
CM_NULLPTR, CM_NULLPTR, indent.Next());
|
2013-08-22 13:30:19 +04:00
|
|
|
os << indent << "endif()\n";
|
2008-01-28 16:38:36 +03:00
|
|
|
files.clear();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-07-02 22:56:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmInstallExportGenerator::GenerateScriptActions(std::ostream& os,
|
|
|
|
Indent const& indent)
|
|
|
|
{
|
2009-01-07 22:16:40 +03:00
|
|
|
// Remove old per-configuration export files if the main changes.
|
|
|
|
std::string installedDir = "$ENV{DESTDIR}";
|
2015-02-11 19:48:02 +03:00
|
|
|
installedDir += this->ConvertToAbsoluteDestination(this->Destination);
|
2009-01-07 22:16:40 +03:00
|
|
|
installedDir += "/";
|
|
|
|
std::string installedFile = installedDir;
|
|
|
|
installedFile += this->FileName;
|
2013-08-22 13:30:19 +04:00
|
|
|
os << indent << "if(EXISTS \"" << installedFile << "\")\n";
|
2009-01-07 22:16:40 +03:00
|
|
|
Indent indentN = indent.Next();
|
|
|
|
Indent indentNN = indentN.Next();
|
|
|
|
Indent indentNNN = indentNN.Next();
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2013-08-22 13:30:19 +04:00
|
|
|
os << indentN << "file(DIFFERENT EXPORT_FILE_CHANGED FILES\n"
|
2009-01-07 22:16:40 +03:00
|
|
|
<< indentN << " \"" << installedFile << "\"\n"
|
|
|
|
<< indentN << " \"" << this->MainImportFile << "\")\n";
|
2013-08-22 13:30:19 +04:00
|
|
|
os << indentN << "if(EXPORT_FILE_CHANGED)\n";
|
|
|
|
os << indentNN << "file(GLOB OLD_CONFIG_FILES \"" << installedDir
|
2009-01-07 22:16:40 +03:00
|
|
|
<< this->EFGen->GetConfigImportFileGlob() << "\")\n";
|
2013-08-22 13:30:19 +04:00
|
|
|
os << indentNN << "if(OLD_CONFIG_FILES)\n";
|
|
|
|
os << indentNNN << "message(STATUS \"Old export file \\\"" << installedFile
|
2009-01-07 22:16:40 +03:00
|
|
|
<< "\\\" will be replaced. Removing files [${OLD_CONFIG_FILES}].\")\n";
|
2013-08-22 13:30:19 +04:00
|
|
|
os << indentNNN << "file(REMOVE ${OLD_CONFIG_FILES})\n";
|
|
|
|
os << indentNN << "endif()\n";
|
|
|
|
os << indentN << "endif()\n";
|
|
|
|
os << indent << "endif()\n";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2009-01-07 22:16:40 +03:00
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
// Install the main export file.
|
|
|
|
std::vector<std::string> files;
|
|
|
|
files.push_back(this->MainImportFile);
|
2016-05-16 17:34:04 +03:00
|
|
|
this->AddInstallRule(os, this->Destination, cmInstallType_FILES, files,
|
2016-06-27 23:44:16 +03:00
|
|
|
false, this->FilePermissions.c_str(), CM_NULLPTR,
|
|
|
|
CM_NULLPTR, CM_NULLPTR, indent);
|
2007-06-19 21:10:21 +04:00
|
|
|
}
|