~ubuntu-branches/ubuntu/jaunty/cmake/jaunty-security

« back to all changes in this revision

Viewing changes to Source/CPack/cmCPackZIPGenerator.cxx

  • Committer: Bazaar Package Importer
  • Author(s): A. Maitland Bottoms
  • Date: 2006-06-18 16:34:11 UTC
  • mfrom: (1.4.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060618163411-pi234s3v6jwlcmof
Tags: 2.4.2-1
* New upstream release (Closes: #338324)
* Put cmake .vim files into /usr/share/vim/addons/plugin/
  where they can be used. (Closes: #366663)
* Install cmake-mode.el so it can be used. (Closes: #366664)
* Ensure cmake FindKDE locates KDE libraries on Debian
  based distributions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*=========================================================================
 
2
 
 
3
  Program:   CMake - Cross-Platform Makefile Generator
 
4
  Module:    $RCSfile: cmCPackZIPGenerator.cxx,v $
 
5
  Language:  C++
 
6
  Date:      $Date: 2006/05/11 14:33:21 $
 
7
  Version:   $Revision: 1.2.2.2 $
 
8
 
 
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.
 
11
 
 
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.
 
15
 
 
16
=========================================================================*/
 
17
 
 
18
#include "cmCPackZIPGenerator.h"
 
19
 
 
20
#include "cmake.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"
 
27
 
 
28
#include <cmsys/SystemTools.hxx>
 
29
 
 
30
//----------------------------------------------------------------------
 
31
cmCPackZIPGenerator::cmCPackZIPGenerator()
 
32
{
 
33
}
 
34
 
 
35
//----------------------------------------------------------------------
 
36
cmCPackZIPGenerator::~cmCPackZIPGenerator()
 
37
{
 
38
}
 
39
 
 
40
//----------------------------------------------------------------------
 
41
int cmCPackZIPGenerator::InitializeInternal()
 
42
{
 
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;
 
49
  bool found = false;
 
50
  if ( pkgPath.empty() )
 
51
    {
 
52
    cmCPackLogger(cmCPackLog::LOG_DEBUG, "Cannot find WinZip" << std::endl);
 
53
    }
 
54
  else
 
55
    {
 
56
    this->ZipStyle = cmCPackZIPGenerator::StyleWinZip;
 
57
    found = true;
 
58
    }
 
59
  if ( !found )
 
60
    {
 
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() )
 
66
      {
 
67
      cmCPackLogger(cmCPackLog::LOG_DEBUG, "Cannot find unix ZIP"
 
68
        << std::endl);
 
69
      }
 
70
    else
 
71
      {
 
72
      this->ZipStyle = cmCPackZIPGenerator::StyleUnixZip;
 
73
      found = true;
 
74
      }
 
75
    }
 
76
  if ( !found )
 
77
    {
 
78
    cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find a sutable ZIP program"
 
79
      << std::endl);
 
80
    return 0;
 
81
    }
 
82
  this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
 
83
  cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Found ZIP program: "
 
84
    << pkgPath.c_str()
 
85
    << std::endl);
 
86
  return this->Superclass::InitializeInternal();
 
87
}
 
88
 
 
89
//----------------------------------------------------------------------
 
90
int cmCPackZIPGenerator::CompressFiles(const char* outFileName,
 
91
  const char* toplevel, const std::vector<std::string>& files)
 
92
{
 
93
  std::string tempFileName;
 
94
  cmOStringStream dmgCmd;
 
95
  switch ( this->ZipStyle )
 
96
    {
 
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() << "\"";
 
103
    break;
 
104
  case cmCPackZIPGenerator::StyleUnixZip:
 
105
    dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
 
106
      << "\" \"" << outFileName
 
107
      << "\"";
 
108
    break;
 
109
  default:
 
110
    cmCPackLogger(cmCPackLog::LOG_ERROR, "Unknown ZIP style"
 
111
      << std::endl);
 
112
    return 0;
 
113
    }
 
114
  if(tempFileName.size())
 
115
    {
 
116
    cmGeneratedFileStream out(tempFileName.c_str());
 
117
    std::vector<std::string>::const_iterator fileIt;
 
118
    for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt )
 
119
      {
 
120
      out << "\""
 
121
          << cmSystemTools::RelativePath(toplevel, fileIt->c_str())
 
122
          << "\"" << std::endl;
 
123
      }
 
124
    }
 
125
  else
 
126
    {
 
127
  std::vector<std::string>::const_iterator fileIt;
 
128
  for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt )
 
129
    {
 
130
    dmgCmd << " \""
 
131
      << cmSystemTools::RelativePath(toplevel, fileIt->c_str())
 
132
      << "\"";
 
133
      }
 
134
    }
 
135
  std::string output;
 
136
  int retVal = -1;
 
137
  int res = cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output,
 
138
    &retVal, toplevel, this->GeneratorVerbose, 0);
 
139
  if ( !res || retVal )
 
140
    {
 
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);
 
150
    return 0;
 
151
    }
 
152
  return 1;
 
153
}