1
/*=========================================================================
3
Program: CMake - Cross-Platform Makefile Generator
4
Module: $RCSfile: cmCPackZIPGenerator.cxx,v $
6
Date: $Date: 2006/05/11 14:33:21 $
7
Version: $Revision: 1.2.2.2 $
9
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12
This software is distributed WITHOUT ANY WARRANTY; without even
13
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14
PURPOSE. See the above copyright notices for more information.
16
=========================================================================*/
18
#include "cmCPackZIPGenerator.h"
21
#include "cmGlobalGenerator.h"
22
#include "cmLocalGenerator.h"
23
#include "cmSystemTools.h"
24
#include "cmMakefile.h"
25
#include "cmGeneratedFileStream.h"
26
#include "cmCPackLog.h"
28
#include <cmsys/SystemTools.hxx>
30
//----------------------------------------------------------------------
31
cmCPackZIPGenerator::cmCPackZIPGenerator()
35
//----------------------------------------------------------------------
36
cmCPackZIPGenerator::~cmCPackZIPGenerator()
40
//----------------------------------------------------------------------
41
int cmCPackZIPGenerator::InitializeInternal()
43
this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1");
44
std::vector<std::string> path;
45
std::string pkgPath = "c:/Program Files/WinZip";
46
path.push_back(pkgPath);
47
pkgPath = cmSystemTools::FindProgram("wzzip", path, false);
48
this->ZipStyle = cmCPackZIPGenerator::StyleUnkown;
50
if ( pkgPath.empty() )
52
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Cannot find WinZip" << std::endl);
56
this->ZipStyle = cmCPackZIPGenerator::StyleWinZip;
61
path.erase(path.begin(), path.end());
62
pkgPath = "c:/cygwin/bin";
63
path.push_back(pkgPath);
64
pkgPath = cmSystemTools::FindProgram("zip", path, false);
65
if ( pkgPath.empty() )
67
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Cannot find unix ZIP"
72
this->ZipStyle = cmCPackZIPGenerator::StyleUnixZip;
78
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find a sutable ZIP program"
82
this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
83
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Found ZIP program: "
86
return this->Superclass::InitializeInternal();
89
//----------------------------------------------------------------------
90
int cmCPackZIPGenerator::CompressFiles(const char* outFileName,
91
const char* toplevel, const std::vector<std::string>& files)
93
std::string tempFileName;
94
cmOStringStream dmgCmd;
95
switch ( this->ZipStyle )
97
case cmCPackZIPGenerator::StyleWinZip:
98
tempFileName = toplevel;
99
tempFileName += "/winZip.filelist";
100
dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
101
<< "\" -P \"" << outFileName
102
<< "\" @\"" << tempFileName.c_str() << "\"";
104
case cmCPackZIPGenerator::StyleUnixZip:
105
dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
106
<< "\" \"" << outFileName
110
cmCPackLogger(cmCPackLog::LOG_ERROR, "Unknown ZIP style"
114
if(tempFileName.size())
116
cmGeneratedFileStream out(tempFileName.c_str());
117
std::vector<std::string>::const_iterator fileIt;
118
for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt )
121
<< cmSystemTools::RelativePath(toplevel, fileIt->c_str())
122
<< "\"" << std::endl;
127
std::vector<std::string>::const_iterator fileIt;
128
for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt )
131
<< cmSystemTools::RelativePath(toplevel, fileIt->c_str())
137
int res = cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output,
138
&retVal, toplevel, this->GeneratorVerbose, 0);
139
if ( !res || retVal )
141
std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
142
tmpFile += "/CompressZip.log";
143
cmGeneratedFileStream ofs(tmpFile.c_str());
144
ofs << "# Run command: " << dmgCmd.str().c_str() << std::endl
145
<< "# Output:" << std::endl
146
<< output.c_str() << std::endl;
147
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running zip command: "
148
<< dmgCmd.str().c_str() << std::endl
149
<< "Please check " << tmpFile.c_str() << " for errors" << std::endl);