2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2006-04-02 19:20:58 +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.
|
2006-04-02 19:20:58 +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.
|
|
|
|
============================================================================*/
|
2006-04-02 19:20:58 +04:00
|
|
|
|
|
|
|
#include "cmCPackZIPGenerator.h"
|
|
|
|
|
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include "cmGeneratedFileStream.h"
|
|
|
|
#include "cmCPackLog.h"
|
|
|
|
|
|
|
|
#include <cmsys/SystemTools.hxx>
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
cmCPackZIPGenerator::cmCPackZIPGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
cmCPackZIPGenerator::~cmCPackZIPGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2006-04-15 21:02:18 +04:00
|
|
|
int cmCPackZIPGenerator::InitializeInternal()
|
2006-04-02 19:20:58 +04:00
|
|
|
{
|
2006-04-15 21:02:18 +04:00
|
|
|
this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1");
|
2007-07-24 20:52:39 +04:00
|
|
|
this->ReadListFile("CPackZIP.cmake");
|
|
|
|
if ((!this->IsSet("ZIP_EXECUTABLE"))
|
|
|
|
|| (!this->IsSet("CPACK_ZIP_COMMAND")))
|
2006-04-02 19:20:58 +04:00
|
|
|
{
|
2007-06-14 21:57:00 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find a suitable ZIP program"
|
2006-04-02 19:20:58 +04:00
|
|
|
<< std::endl);
|
|
|
|
return 0;
|
|
|
|
}
|
2006-04-15 21:02:18 +04:00
|
|
|
return this->Superclass::InitializeInternal();
|
2006-04-02 19:20:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int cmCPackZIPGenerator::CompressFiles(const char* outFileName,
|
|
|
|
const char* toplevel, const std::vector<std::string>& files)
|
|
|
|
{
|
2006-05-11 17:37:48 +04:00
|
|
|
std::string tempFileName;
|
2006-09-21 23:09:34 +04:00
|
|
|
tempFileName = toplevel;
|
|
|
|
tempFileName += "/winZip.filelist";
|
2007-07-27 18:55:24 +04:00
|
|
|
bool needQuotesInFile = cmSystemTools::IsOn(
|
|
|
|
this->GetOption("CPACK_ZIP_NEED_QUOTES"));
|
2007-07-24 20:52:39 +04:00
|
|
|
|
|
|
|
std::string cmd = this->GetOption("CPACK_ZIP_COMMAND");
|
|
|
|
cmsys::SystemTools::ReplaceString(cmd, "<ARCHIVE>", outFileName);
|
|
|
|
cmsys::SystemTools::ReplaceString(cmd, "<FILELIST>", "winZip.filelist");
|
|
|
|
|
|
|
|
{ // the scope is needed for cmGeneratedFileStream
|
|
|
|
cmGeneratedFileStream out(tempFileName.c_str());
|
|
|
|
std::vector<std::string>::const_iterator fileIt;
|
|
|
|
for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt )
|
2006-04-02 19:20:58 +04:00
|
|
|
{
|
2007-07-24 20:52:39 +04:00
|
|
|
if ( needQuotesInFile )
|
2006-05-11 17:37:48 +04:00
|
|
|
{
|
2007-07-24 20:52:39 +04:00
|
|
|
out << "\"";
|
2006-05-11 17:37:48 +04:00
|
|
|
}
|
2007-07-24 20:52:39 +04:00
|
|
|
out << cmSystemTools::RelativePath(toplevel, fileIt->c_str());
|
|
|
|
if ( needQuotesInFile )
|
2006-05-11 17:37:48 +04:00
|
|
|
{
|
2007-07-24 20:52:39 +04:00
|
|
|
out << "\"";
|
2006-05-11 17:37:48 +04:00
|
|
|
}
|
2007-07-24 20:52:39 +04:00
|
|
|
out << std::endl;
|
2006-04-02 19:20:58 +04:00
|
|
|
}
|
2007-07-24 20:52:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-02 19:20:58 +04:00
|
|
|
std::string output;
|
|
|
|
int retVal = -1;
|
2007-07-24 20:52:39 +04:00
|
|
|
int res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output,
|
2006-04-02 19:20:58 +04:00
|
|
|
&retVal, toplevel, this->GeneratorVerbose, 0);
|
2007-07-24 20:52:39 +04:00
|
|
|
|
2006-04-02 19:20:58 +04:00
|
|
|
if ( !res || retVal )
|
|
|
|
{
|
|
|
|
std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
|
|
|
|
tmpFile += "/CompressZip.log";
|
|
|
|
cmGeneratedFileStream ofs(tmpFile.c_str());
|
2007-07-24 20:52:39 +04:00
|
|
|
ofs << "# Run command: " << cmd.c_str() << std::endl
|
2006-04-02 19:20:58 +04:00
|
|
|
<< "# Output:" << std::endl
|
|
|
|
<< output.c_str() << std::endl;
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running zip command: "
|
2007-07-24 20:52:39 +04:00
|
|
|
<< cmd.c_str() << std::endl
|
2006-04-02 19:20:58 +04:00
|
|
|
<< "Please check " << tmpFile.c_str() << " for errors" << std::endl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|