2009-10-30 20:10:56 +03:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
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.
|
|
|
|
============================================================================*/
|
|
|
|
|
|
|
|
#include "cmCPackArchiveGenerator.h"
|
|
|
|
|
|
|
|
#include "cmake.h"
|
|
|
|
#include "cmGlobalGenerator.h"
|
|
|
|
#include "cmLocalGenerator.h"
|
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmGeneratedFileStream.h"
|
|
|
|
#include "cmCPackLog.h"
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <cmsys/SystemTools.hxx>
|
2010-08-06 01:06:10 +04:00
|
|
|
#include <cm_libarchive.h>
|
2009-10-30 20:10:56 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2010-08-24 23:41:32 +04:00
|
|
|
cmCPackArchiveGenerator::cmCPackArchiveGenerator(cmArchiveWrite::Compress t,
|
|
|
|
cmArchiveWrite::Type at)
|
2009-10-30 20:10:56 +03:00
|
|
|
{
|
|
|
|
this->Compress = t;
|
|
|
|
this->Archive = at;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
cmCPackArchiveGenerator::~cmCPackArchiveGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int cmCPackArchiveGenerator::InitializeInternal()
|
|
|
|
{
|
|
|
|
this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1");
|
|
|
|
return this->Superclass::InitializeInternal();
|
|
|
|
}
|
|
|
|
|
2010-08-11 21:48:39 +04:00
|
|
|
int cmCPackArchiveGenerator::PackageFiles()
|
2009-10-30 20:10:56 +03:00
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: "
|
2010-08-11 21:48:39 +04:00
|
|
|
<< toplevel << std::endl);
|
|
|
|
|
2009-10-30 20:10:56 +03:00
|
|
|
// Open binary stream
|
2010-08-24 23:41:32 +04:00
|
|
|
cmGeneratedFileStream gf;
|
|
|
|
gf.Open(packageFileNames[0].c_str(), false, true);
|
|
|
|
// Add an eventual header to the archive
|
|
|
|
if (!GenerateHeader(&gf))
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem to generate Header for archive < "
|
|
|
|
<< packageFileNames[0]
|
|
|
|
<< ">." << std::endl);
|
|
|
|
}
|
|
|
|
// create a new archive
|
|
|
|
cmArchiveWrite archive(gf,this->Compress, this->Archive);
|
|
|
|
if (!archive)
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem to create archive < "
|
|
|
|
<< packageFileNames[0]
|
|
|
|
<< ">. ERROR ="
|
|
|
|
<< archive.GetError()
|
|
|
|
<< std::endl);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-10-30 20:10:56 +03:00
|
|
|
std::vector<std::string>::const_iterator fileIt;
|
2009-11-09 17:58:03 +03:00
|
|
|
std::string dir = cmSystemTools::GetCurrentWorkingDirectory();
|
2010-08-11 21:48:39 +04:00
|
|
|
cmSystemTools::ChangeDirectory(toplevel.c_str());
|
2009-10-30 20:10:56 +03:00
|
|
|
for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt )
|
|
|
|
{
|
|
|
|
// Get the relative path to the file
|
2010-08-11 21:48:39 +04:00
|
|
|
std::string rp = cmSystemTools::RelativePath(toplevel.c_str(), fileIt->c_str());
|
2010-08-24 23:41:32 +04:00
|
|
|
archive.Add(rp);
|
|
|
|
if(!archive)
|
2009-10-30 20:10:56 +03:00
|
|
|
{
|
2010-08-24 23:41:32 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem while adding file< "
|
|
|
|
<< *fileIt
|
|
|
|
<< "> to archive <"
|
|
|
|
<< packageFileNames[0] << "> .ERROR ="
|
|
|
|
<< archive.GetError()
|
|
|
|
<< std::endl);
|
|
|
|
return 0;
|
2009-10-30 20:10:56 +03:00
|
|
|
}
|
|
|
|
}
|
2009-11-09 17:58:03 +03:00
|
|
|
cmSystemTools::ChangeDirectory(dir.c_str());
|
2010-08-24 23:41:32 +04:00
|
|
|
// The destructor of cmArchiveWrite will close and finish the write
|
2009-10-30 20:10:56 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int cmCPackArchiveGenerator::GenerateHeader(std::ostream*)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|