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>
|
|
|
|
|
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"
|
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"
|
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(
|
2012-03-01 14:52:32 +04:00
|
|
|
cmExportSet* exportSet,
|
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,
|
2013-06-04 18:47:57 +04:00
|
|
|
bool exportOld,
|
2008-01-28 16:38:36 +03:00
|
|
|
cmMakefile* mf)
|
2007-07-02 22:56:57 +04:00
|
|
|
:cmInstallGenerator(destination, configurations, component)
|
2012-03-01 14:52:32 +04:00
|
|
|
,ExportSet(exportSet)
|
2007-06-19 21:10:21 +04:00
|
|
|
,FilePermissions(file_permissions)
|
2008-01-28 16:38:36 +03:00
|
|
|
,FileName(filename)
|
|
|
|
,Namespace(name_space)
|
2013-06-04 18:47:57 +04:00
|
|
|
,ExportOld(exportOld)
|
2008-01-28 16:38:36 +03:00
|
|
|
,Makefile(mf)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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 +=
|
2014-03-11 03:04:11 +04:00
|
|
|
cmSystemTools::ComputeStringMD5(this->Destination);
|
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
|
|
|
// Skip empty sets.
|
2012-03-01 14:52:32 +04:00
|
|
|
if(ExportSet->GetTargetExports()->empty())
|
2007-06-19 21:10:21 +04:00
|
|
|
{
|
2008-01-28 16:38:36 +03:00
|
|
|
cmOStringStream e;
|
2012-03-01 14:52:32 +04:00
|
|
|
e << "INSTALL(EXPORT) given unknown export \""
|
|
|
|
<< ExportSet->GetName() << "\"";
|
2008-01-28 16:38:36 +03:00
|
|
|
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->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);
|
2008-01-28 16:38:36 +03:00
|
|
|
if(this->ConfigurationTypes->empty())
|
2007-06-19 21:10:21 +04:00
|
|
|
{
|
2014-02-10 07:48:34 +04:00
|
|
|
if(!this->ConfigurationName.empty())
|
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
|
|
|
{
|
2014-03-11 03:04:11 +04:00
|
|
|
this->EFGen->AddConfiguration(*ci);
|
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;
|
2014-02-10 09:21:34 +04:00
|
|
|
for(std::map<std::string, std::string>::const_iterator
|
2008-01-28 16:38:36 +03:00
|
|
|
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);
|
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";
|
2012-02-27 20:26:38 +04:00
|
|
|
this->AddInstallRule(os, cmInstallType_FILES, files, false,
|
2008-01-28 16:38:36 +03:00
|
|
|
this->FilePermissions.c_str(), 0, 0, 0,
|
|
|
|
indent.Next());
|
2013-08-22 13:30:19 +04:00
|
|
|
os << indent << "endif()\n";
|
2008-01-28 16:38:36 +03:00
|
|
|
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;
|
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();
|
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";
|
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);
|
2012-02-27 20:26:38 +04:00
|
|
|
this->AddInstallRule(os, cmInstallType_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
|
|
|
}
|