1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCPackZIPGenerator.cxx,v $
6 Date: $Date: 2007/07/27 14:55:24 $
7 Version: $Revision: 1.11 $
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"
20 #include "cmSystemTools.h"
21 #include "cmGeneratedFileStream.h"
22 #include "cmCPackLog.h"
24 #include <cmsys/SystemTools.hxx>
26 //----------------------------------------------------------------------
27 cmCPackZIPGenerator::cmCPackZIPGenerator()
31 //----------------------------------------------------------------------
32 cmCPackZIPGenerator::~cmCPackZIPGenerator()
36 //----------------------------------------------------------------------
37 int cmCPackZIPGenerator::InitializeInternal()
39 this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1");
40 this->ReadListFile("CPackZIP.cmake");
41 if ((!this->IsSet("ZIP_EXECUTABLE"))
42 || (!this->IsSet("CPACK_ZIP_COMMAND")))
44 cmCPackLogger(cmCPackLog::LOG_ERROR
, "Cannot find a suitable ZIP program"
48 return this->Superclass::InitializeInternal();
51 //----------------------------------------------------------------------
52 int cmCPackZIPGenerator::CompressFiles(const char* outFileName
,
53 const char* toplevel
, const std::vector
<std::string
>& files
)
55 std::string tempFileName
;
56 tempFileName
= toplevel
;
57 tempFileName
+= "/winZip.filelist";
58 bool needQuotesInFile
= cmSystemTools::IsOn(
59 this->GetOption("CPACK_ZIP_NEED_QUOTES"));
61 std::string cmd
= this->GetOption("CPACK_ZIP_COMMAND");
62 cmsys::SystemTools::ReplaceString(cmd
, "<ARCHIVE>", outFileName
);
63 cmsys::SystemTools::ReplaceString(cmd
, "<FILELIST>", "winZip.filelist");
65 { // the scope is needed for cmGeneratedFileStream
66 cmGeneratedFileStream
out(tempFileName
.c_str());
67 std::vector
<std::string
>::const_iterator fileIt
;
68 for ( fileIt
= files
.begin(); fileIt
!= files
.end(); ++ fileIt
)
70 if ( needQuotesInFile
)
74 out
<< cmSystemTools::RelativePath(toplevel
, fileIt
->c_str());
75 if ( needQuotesInFile
)
86 int res
= cmSystemTools::RunSingleCommand(cmd
.c_str(), &output
,
87 &retVal
, toplevel
, this->GeneratorVerbose
, 0);
91 std::string tmpFile
= this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
92 tmpFile
+= "/CompressZip.log";
93 cmGeneratedFileStream
ofs(tmpFile
.c_str());
94 ofs
<< "# Run command: " << cmd
.c_str() << std::endl
95 << "# Output:" << std::endl
96 << output
.c_str() << std::endl
;
97 cmCPackLogger(cmCPackLog::LOG_ERROR
, "Problem running zip command: "
98 << cmd
.c_str() << std::endl
99 << "Please check " << tmpFile
.c_str() << " for errors" << std::endl
);