ENH: add ReadListFile() to cmCPackGenericGenerator, so cmMakefile can be

private again
-convert the ZIP generator to use a cmake script instead of hardcoding
everything (CPackZIP.cmake)

Alex
This commit is contained in:
Alexander Neundorf 2007-07-24 12:52:39 -04:00
parent 4ae802d9c1
commit 919265516e
6 changed files with 90 additions and 136 deletions

27
Modules/CPackZIP.cmake Normal file
View File

@ -0,0 +1,27 @@
IF(CMAKE_BINARY_DIR)
MESSAGE(FATAL_ERROR "CPackZIP.cmake may only be used by CPack internally.")
ENDIF(CMAKE_BINARY_DIR)
FIND_PROGRAM(ZIP_EXECUTABLE wzzip PATHS "$ENV{ProgramFiles}/WinZip")
IF(ZIP_EXECUTABLE)
SET(CPACK_ZIP_COMMAND "\"${ZIP_EXECUTABLE}\" -P \"<ARCHIVE>\" @<FILELIST>")
SET(CPACK_ZIP_NEED_QUOTES TRUE)
ENDIF(ZIP_EXECUTABLE)
IF(NOT ZIP_EXECUTABLE)
FIND_PROGRAM(ZIP_EXECUTABLE 7z PATHS "$ENV{ProgramFiles}/7-Zip")
IF(ZIP_EXECUTABLE)
SET(CPACK_ZIP_COMMAND "\"${ZIP_EXECUTABLE}\" a -tzip \"<ARCHIVE>\" @<FILELIST>")
SET(CPACK_ZIP_NEED_QUOTES TRUE)
ENDIF(ZIP_EXECUTABLE)
ENDIF(NOT ZIP_EXECUTABLE)
IF(NOT ZIP_EXECUTABLE)
FIND_PACKAGE(Cygwin)
FIND_PROGRAM(ZIP_EXECUTABLE zip PATHS "${CYGWIN_INSTALL_PATH}/bin")
IF(ZIP_EXECUTABLE)
SET(CPACK_ZIP_COMMAND "\"${ZIP_EXECUTABLE}\" -r \"<ARCHIVE>\" . -i@<FILELIST>")
SET(CPACK_ZIP_NEED_QUOTES FALSE)
ENDIF(ZIP_EXECUTABLE)
ENDIF(NOT ZIP_EXECUTABLE)

View File

@ -30,3 +30,8 @@ IF(CMAKE_COMPILER_IS_GNUCXX)
SET(CMAKE_CXX_LINK_EXECUTABLE
"<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Wl,-lstdc++,-lgcc,-lc -lnss_files -lnss_dns -lresolv")
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
SET(CMAKE_CXX_LINK_SHARED_LIBRARY)
SET(CMAKE_CXX_LINK_MODULE_LIBRARY)
SET(CMAKE_C_LINK_SHARED_LIBRARY)
SET(CMAKE_C_LINK_MODULE_LIBRARY)

View File

@ -32,14 +32,14 @@
cmCPackGenericGenerator::cmCPackGenericGenerator()
{
this->GeneratorVerbose = false;
this->Makefile = 0;
this->MakefileMap = 0;
this->Logger = 0;
}
//----------------------------------------------------------------------
cmCPackGenericGenerator::~cmCPackGenericGenerator()
{
this->Makefile = 0;
this->MakefileMap = 0;
}
//----------------------------------------------------------------------
@ -392,7 +392,7 @@ int cmCPackGenericGenerator::InstallProjectViaInstallScript(
tempInstallDirectory);
this->SetOptionIfNotSet("CMAKE_CURRENT_SOURCE_DIR",
tempInstallDirectory);
int res = this->Makefile->ReadListFile(0, installScript.c_str());
int res = this->MakefileMap->ReadListFile(0, installScript.c_str());
if ( cmSystemTools::GetErrorOccuredFlag() || !res )
{
return 0;
@ -454,7 +454,7 @@ int cmCPackGenericGenerator::InstallProjectViaInstallCMakeProjects(
const char* buildConfig = this->GetOption("CPACK_BUILD_CONFIG");
cmGlobalGenerator* globalGenerator
= this->Makefile->GetCMakeInstance()->CreateGlobalGenerator(
= this->MakefileMap->GetCMakeInstance()->CreateGlobalGenerator(
cmakeGenerator);
// set the global flag for unix style paths on cmSystemTools as
// soon as the generator is set. This allows gmake to be used
@ -464,9 +464,9 @@ int cmCPackGenericGenerator::InstallProjectViaInstallCMakeProjects(
// Does this generator require pre-install?
if ( globalGenerator->GetPreinstallTargetName() )
{
globalGenerator->FindMakeProgram(this->Makefile);
globalGenerator->FindMakeProgram(this->MakefileMap);
const char* cmakeMakeProgram
= this->Makefile->GetDefinition("CMAKE_MAKE_PROGRAM");
= this->MakefileMap->GetDefinition("CMAKE_MAKE_PROGRAM");
std::string buildCommand
= globalGenerator->GenerateBuildCommand(cmakeMakeProgram,
installProjectName.c_str(), 0,
@ -550,11 +550,18 @@ int cmCPackGenericGenerator::InstallProjectViaInstallCMakeProjects(
return 1;
}
//----------------------------------------------------------------------
bool cmCPackGenericGenerator::ReadListFile(const char* moduleName)
{
std::string fullPath = this->MakefileMap->GetModulesFile(moduleName);
return this->MakefileMap->ReadListFile(0, fullPath.c_str());
}
//----------------------------------------------------------------------
void cmCPackGenericGenerator::SetOptionIfNotSet(const char* op,
const char* value)
{
const char* def = this->Makefile->GetDefinition(op);
const char* def = this->MakefileMap->GetDefinition(op);
if ( def && *def )
{
return;
@ -571,12 +578,12 @@ void cmCPackGenericGenerator::SetOption(const char* op, const char* value)
}
if ( !value )
{
this->Makefile->RemoveDefinition(op);
this->MakefileMap->RemoveDefinition(op);
return;
}
cmCPackLogger(cmCPackLog::LOG_DEBUG, this->GetNameOfClass()
<< "::SetOption(" << op << ", " << value << ")" << std::endl);
this->Makefile->AddDefinition(op, value);
this->MakefileMap->AddDefinition(op, value);
}
//----------------------------------------------------------------------
@ -680,7 +687,7 @@ int cmCPackGenericGenerator::ProcessGenerator()
int cmCPackGenericGenerator::Initialize(const char* name, cmMakefile* mf,
const char* argv0)
{
this->Makefile = mf;
this->MakefileMap = mf;
this->Name = name;
if ( !this->FindRunningCMake(argv0) )
{
@ -697,10 +704,16 @@ int cmCPackGenericGenerator::InitializeInternal()
return 1;
}
//----------------------------------------------------------------------
bool cmCPackGenericGenerator::IsSet(const char* name) const
{
return this->MakefileMap->IsSet(name);
}
//----------------------------------------------------------------------
const char* cmCPackGenericGenerator::GetOption(const char* op)
{
return this->Makefile->GetDefinition(op);
return this->MakefileMap->GetDefinition(op);
}
//----------------------------------------------------------------------
@ -913,7 +926,7 @@ std::string cmCPackGenericGenerator::FindTemplate(const char* name)
{
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Look for template: "
<< (name ? name : "(NULL)") << std::endl);
std::string ffile = this->Makefile->GetModulesFile(name);
std::string ffile = this->MakefileMap->GetModulesFile(name);
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Found template: "
<< ffile.c_str() << std::endl);
return ffile;
@ -923,7 +936,7 @@ std::string cmCPackGenericGenerator::FindTemplate(const char* name)
bool cmCPackGenericGenerator::ConfigureString(const std::string& inString,
std::string& outString)
{
this->Makefile->ConfigureString(inString,
this->MakefileMap->ConfigureString(inString,
outString, true, false);
return true;
}
@ -932,7 +945,7 @@ bool cmCPackGenericGenerator::ConfigureString(const std::string& inString,
bool cmCPackGenericGenerator::ConfigureFile(const char* inName,
const char* outName, bool copyOnly /* = false */)
{
return this->Makefile->ConfigureFile(inName, outName,
return this->MakefileMap->ConfigureFile(inName, outName,
copyOnly, true, false) == 1;
}

View File

@ -80,6 +80,7 @@ public:
void SetOption(const char* op, const char* value);
void SetOptionIfNotSet(const char* op, const char* value);
const char* GetOption(const char* op);
bool IsSet(const char* name) const;
//! Set all the variables
int FindRunningCMake(const char* arg0);
@ -89,6 +90,8 @@ public:
//! Display verbose information via logger
void DisplayVerboseOutput(const char* msg, float progress);
bool ReadListFile(const char* moduleName);
protected:
int PrepareNames();
@ -129,8 +132,8 @@ protected:
std::string CMakeRoot;
cmCPackLog* Logger;
cmMakefile* Makefile;
private:
cmMakefile* MakefileMap;
};
#endif

View File

@ -17,11 +17,7 @@
#include "cmCPackZIPGenerator.h"
#include "cmake.h"
#include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h"
#include "cmSystemTools.h"
#include "cmMakefile.h"
#include "cmGeneratedFileStream.h"
#include "cmCPackLog.h"
@ -41,67 +37,14 @@ cmCPackZIPGenerator::~cmCPackZIPGenerator()
int cmCPackZIPGenerator::InitializeInternal()
{
this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1");
std::vector<std::string> path;
std::string pkgPath = "c:/Program Files/WinZip";
path.push_back(pkgPath);
pkgPath = cmSystemTools::FindProgram("wzzip", path, false);
this->ZipStyle = cmCPackZIPGenerator::StyleUnkown;
bool found = false;
if ( pkgPath.empty() )
{
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Cannot find WinZip" << std::endl);
}
else
{
this->ZipStyle = cmCPackZIPGenerator::StyleWinZip;
found = true;
}
if ( !found )
{
pkgPath = "c:/Program Files/7-Zip";
path.push_back(pkgPath);
pkgPath = cmSystemTools::FindProgram("7z", path, false);
if ( pkgPath.empty() )
{
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Cannot find 7ZIP"
<< std::endl);
}
else
{
this->ZipStyle = cmCPackZIPGenerator::Style7Zip;
found = true;
}
}
if ( !found )
{
path.erase(path.begin(), path.end());
pkgPath = "c:/cygwin/bin";
path.push_back(pkgPath);
pkgPath = cmSystemTools::FindProgram("zip", path, false);
if ( pkgPath.empty() )
{
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Cannot find unix ZIP"
<< std::endl);
}
else
{
this->ZipStyle = cmCPackZIPGenerator::StyleUnixZip;
found = true;
}
}
if ( !found )
this->ReadListFile("CPackZIP.cmake");
if ((!this->IsSet("ZIP_EXECUTABLE"))
|| (!this->IsSet("CPACK_ZIP_COMMAND")))
{
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find a suitable ZIP program"
<< std::endl);
return 0;
}
this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Found ZIP program: "
<< pkgPath.c_str()
<< std::endl);
return this->Superclass::InitializeInternal();
}
@ -112,75 +55,46 @@ int cmCPackZIPGenerator::CompressFiles(const char* outFileName,
std::string tempFileName;
tempFileName = toplevel;
tempFileName += "/winZip.filelist";
bool needQuotesInFile = false;
cmOStringStream dmgCmd;
switch ( this->ZipStyle )
bool needQuotesInFile = cmSystemTools::IsOn(this->GetOption("CPACK_ZIP_NEED_QUOTES"));
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 )
{
case cmCPackZIPGenerator::StyleWinZip:
dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
<< "\" -P \"" << outFileName
<< "\" @winZip.filelist";
needQuotesInFile = true;
break;
case cmCPackZIPGenerator::Style7Zip:
// this is the zip generator, so tell 7zip to generate zip files
dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
<< "\" a -tzip \"" << outFileName
<< "\" @winZip.filelist";
needQuotesInFile = true;
break;
case cmCPackZIPGenerator::StyleUnixZip:
dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
<< "\" -r \"" << outFileName
<< "\" . -i@winZip.filelist";
break;
default:
cmCPackLogger(cmCPackLog::LOG_ERROR, "Unknown ZIP style"
<< std::endl);
return 0;
}
if(tempFileName.size())
{
cmGeneratedFileStream out(tempFileName.c_str());
std::vector<std::string>::const_iterator fileIt;
for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt )
if ( needQuotesInFile )
{
if ( needQuotesInFile )
{
out << "\"";
}
out << cmSystemTools::RelativePath(toplevel, fileIt->c_str());
if ( needQuotesInFile )
{
out << "\"";
}
out << std::endl;
out << "\"";
}
}
else
{
std::vector<std::string>::const_iterator fileIt;
for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt )
out << cmSystemTools::RelativePath(toplevel, fileIt->c_str());
if ( needQuotesInFile )
{
dmgCmd << " \""
<< cmSystemTools::RelativePath(toplevel, fileIt->c_str())
<< "\"";
out << "\"";
}
out << std::endl;
}
}
std::string output;
int retVal = -1;
int res = cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output,
int res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output,
&retVal, toplevel, this->GeneratorVerbose, 0);
if ( !res || retVal )
{
std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
tmpFile += "/CompressZip.log";
cmGeneratedFileStream ofs(tmpFile.c_str());
ofs << "# Run command: " << dmgCmd.str().c_str() << std::endl
ofs << "# Run command: " << cmd.c_str() << std::endl
<< "# Output:" << std::endl
<< output.c_str() << std::endl;
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running zip command: "
<< dmgCmd.str().c_str() << std::endl
<< cmd.c_str() << std::endl
<< "Please check " << tmpFile.c_str() << " for errors" << std::endl);
return 0;
}

View File

@ -37,14 +37,6 @@ public:
cmCPackZIPGenerator();
virtual ~cmCPackZIPGenerator();
enum ZipStyles
{
StyleUnkown,
StyleWinZip,
StyleUnixZip,
Style7Zip
};
protected:
virtual int InitializeInternal();
int CompressFiles(const char* outFileName, const char* toplevel,