2009-10-02 01:21: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-10-02 01:21: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-10-02 01:21: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>
|
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
#include "cmake.h"
|
2007-06-19 21:10:21 +04:00
|
|
|
#include "cmInstallTargetGenerator.h"
|
|
|
|
#include "cmGeneratedFileStream.h"
|
|
|
|
#include "cmTarget.h"
|
2008-01-28 16:38:36 +03:00
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmLocalGenerator.h"
|
|
|
|
#include "cmGlobalGenerator.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"
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2007-07-02 22:56:57 +04:00
|
|
|
cmInstallExportGenerator::cmInstallExportGenerator(
|
2008-01-28 16:38:36 +03:00
|
|
|
const char* name,
|
2007-07-02 22:56:57 +04:00
|
|
|
const char* destination,
|
|
|
|
const char* file_permissions,
|
|
|
|
std::vector<std::string> const& configurations,
|
|
|
|
const char* component,
|
2008-01-28 16:38:36 +03:00
|
|
|
const char* filename, const char* name_space,
|
|
|
|
cmMakefile* mf)
|
2007-07-02 22:56:57 +04:00
|
|
|
:cmInstallGenerator(destination, configurations, component)
|
2008-01-28 16:38:36 +03:00
|
|
|
,Name(name)
|
2007-06-19 21:10:21 +04:00
|
|
|
,FilePermissions(file_permissions)
|
2008-01-28 16:38:36 +03:00
|
|
|
,FileName(filename)
|
|
|
|
,Namespace(name_space)
|
|
|
|
,Makefile(mf)
|
|
|
|
{
|
|
|
|
this->EFGen = new cmExportInstallFileGenerator(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
this->TempDir = this->Makefile->GetCurrentOutputDirectory();
|
|
|
|
this->TempDir += cmake::GetCMakeFilesDirectory();
|
|
|
|
this->TempDir += "/Export";
|
|
|
|
if(this->Destination.empty())
|
2007-06-19 21:10:21 +04:00
|
|
|
{
|
2008-01-28 16:38:36 +03:00
|
|
|
return;
|
2007-06-19 21:10:21 +04:00
|
|
|
}
|
2008-01-28 16:38:36 +03:00
|
|
|
else
|
2007-06-19 21:10:21 +04:00
|
|
|
{
|
2008-01-28 16:38:36 +03:00
|
|
|
this->TempDir += "/";
|
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
|
|
|
|
if(this->TempDir.size() < max_total_len)
|
2007-06-19 21:10:21 +04:00
|
|
|
{
|
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();
|
|
|
|
if(this->Destination.size() > max_len)
|
2007-06-19 21:10:21 +04:00
|
|
|
{
|
2008-01-28 16:38:36 +03:00
|
|
|
useMD5 = true;
|
2007-06-19 21:10:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-01-28 16:38:36 +03:00
|
|
|
useMD5 = true;
|
2007-08-28 00:04:57 +04:00
|
|
|
}
|
2008-01-28 16:38:36 +03:00
|
|
|
if(useMD5)
|
2007-08-28 00:04:57 +04:00
|
|
|
{
|
2008-01-28 16:38:36 +03:00
|
|
|
// Replace the destination path with a hash to keep it short.
|
|
|
|
this->TempDir +=
|
|
|
|
cmSystemTools::ComputeStringMD5(this->Destination.c_str());
|
2007-08-28 00:04:57 +04:00
|
|
|
}
|
2008-01-28 16:38:36 +03:00
|
|
|
else
|
2007-08-28 00:04:57 +04:00
|
|
|
{
|
2008-01-28 16:38:36 +03:00
|
|
|
std::string dest = this->Destination;
|
|
|
|
// Avoid unix full paths.
|
|
|
|
if(dest[0] == '/')
|
|
|
|
{
|
|
|
|
dest[0] = '_';
|
|
|
|
}
|
|
|
|
// Avoid windows full paths by removing colons.
|
|
|
|
cmSystemTools::ReplaceString(dest, ":", "_");
|
|
|
|
// Avoid relative paths that go up the tree.
|
|
|
|
cmSystemTools::ReplaceString(dest, "../", "__/");
|
|
|
|
// Avoid spaces.
|
|
|
|
cmSystemTools::ReplaceString(dest, " ", "_");
|
|
|
|
this->TempDir += dest;
|
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
|
|
|
// Get the export set requested.
|
|
|
|
ExportSet const* exportSet =
|
|
|
|
this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
|
|
|
|
->GetExportSet(this->Name.c_str());
|
|
|
|
|
|
|
|
// Skip empty sets.
|
|
|
|
if(!exportSet)
|
2007-06-19 21:10:21 +04:00
|
|
|
{
|
2008-01-28 16:38:36 +03:00
|
|
|
cmOStringStream e;
|
|
|
|
e << "INSTALL(EXPORT) given unknown export \"" << this->Name << "\"";
|
|
|
|
cmSystemTools::Error(e.str().c_str());
|
|
|
|
return;
|
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->SetName(this->Name.c_str());
|
|
|
|
this->EFGen->SetExportSet(exportSet);
|
|
|
|
this->EFGen->SetExportFile(this->MainImportFile.c_str());
|
|
|
|
this->EFGen->SetNamespace(this->Namespace.c_str());
|
|
|
|
if(this->ConfigurationTypes->empty())
|
2007-06-19 21:10:21 +04:00
|
|
|
{
|
2008-01-28 16:38:36 +03:00
|
|
|
if(this->ConfigurationName && *this->ConfigurationName)
|
2007-06-19 21:10:21 +04:00
|
|
|
{
|
2008-01-28 16:38:36 +03:00
|
|
|
this->EFGen->AddConfiguration(this->ConfigurationName);
|
2007-06-19 21:10:21 +04:00
|
|
|
}
|
2008-01-28 16:38:36 +03:00
|
|
|
else
|
2007-06-19 21:10:21 +04:00
|
|
|
{
|
2008-01-28 16:38:36 +03:00
|
|
|
this->EFGen->AddConfiguration("");
|
2007-06-19 21:10:21 +04:00
|
|
|
}
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(std::vector<std::string>::const_iterator
|
|
|
|
ci = this->ConfigurationTypes->begin();
|
|
|
|
ci != this->ConfigurationTypes->end(); ++ci)
|
2007-08-28 00:04:57 +04:00
|
|
|
{
|
2008-01-28 16:38:36 +03:00
|
|
|
this->EFGen->AddConfiguration(ci->c_str());
|
2007-08-28 00:04:57 +04:00
|
|
|
}
|
2007-06-19 21:10:21 +04: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
|
|
|
}
|
|
|
|
|
2008-01-28 16:38:36 +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;
|
|
|
|
for(std::map<cmStdString, cmStdString>::const_iterator
|
|
|
|
i = this->EFGen->GetConfigImportFiles().begin();
|
|
|
|
i != this->EFGen->GetConfigImportFiles().end(); ++i)
|
2007-06-19 21:10:21 +04:00
|
|
|
{
|
2008-01-28 16:38:36 +03:00
|
|
|
files.push_back(i->second);
|
|
|
|
std::string config_test = this->CreateConfigTest(i->first.c_str());
|
|
|
|
os << indent << "IF(" << config_test << ")\n";
|
2009-04-27 21:20:57 +04:00
|
|
|
this->AddInstallRule(os, cmTarget::INSTALL_FILES, files, false,
|
2008-01-28 16:38:36 +03:00
|
|
|
this->FilePermissions.c_str(), 0, 0, 0,
|
|
|
|
indent.Next());
|
|
|
|
os << indent << "ENDIF(" << config_test << ")\n";
|
|
|
|
files.clear();
|
2007-06-19 21:10:21 +04: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}";
|
|
|
|
installedDir += this->GetInstallDestination();
|
|
|
|
installedDir += "/";
|
|
|
|
std::string installedFile = installedDir;
|
|
|
|
installedFile += this->FileName;
|
|
|
|
os << indent << "IF(EXISTS \"" << installedFile << "\")\n";
|
|
|
|
Indent indentN = indent.Next();
|
|
|
|
Indent indentNN = indentN.Next();
|
|
|
|
Indent indentNNN = indentNN.Next();
|
|
|
|
os << indentN << "FILE(DIFFERENT EXPORT_FILE_CHANGED FILES\n"
|
|
|
|
<< indentN << " \"" << installedFile << "\"\n"
|
|
|
|
<< indentN << " \"" << this->MainImportFile << "\")\n";
|
|
|
|
os << indentN << "IF(EXPORT_FILE_CHANGED)\n";
|
|
|
|
os << indentNN << "FILE(GLOB OLD_CONFIG_FILES \"" << installedDir
|
|
|
|
<< this->EFGen->GetConfigImportFileGlob() << "\")\n";
|
|
|
|
os << indentNN << "IF(OLD_CONFIG_FILES)\n";
|
|
|
|
os << indentNNN << "MESSAGE(STATUS \"Old export file \\\"" << installedFile
|
|
|
|
<< "\\\" will be replaced. Removing files [${OLD_CONFIG_FILES}].\")\n";
|
|
|
|
os << indentNNN << "FILE(REMOVE ${OLD_CONFIG_FILES})\n";
|
|
|
|
os << indentNN << "ENDIF(OLD_CONFIG_FILES)\n";
|
|
|
|
os << indentN << "ENDIF(EXPORT_FILE_CHANGED)\n";
|
|
|
|
os << indent << "ENDIF()\n";
|
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
// Install the main export file.
|
|
|
|
std::vector<std::string> files;
|
|
|
|
files.push_back(this->MainImportFile);
|
2009-04-27 21:20:57 +04:00
|
|
|
this->AddInstallRule(os, cmTarget::INSTALL_FILES, files, false,
|
2008-01-28 16:38:36 +03:00
|
|
|
this->FilePermissions.c_str(), 0, 0, 0, indent);
|
2007-06-19 21:10:21 +04:00
|
|
|
}
|