Commit 4925e64b authored by Bill Hoffman's avatar Bill Hoffman
Browse files

ENH: add support for cygwin source and binary packaging

parent 1feb4a09
......@@ -388,9 +388,44 @@ IF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
SET(CPACK_SOURCE_STRIP_FILES "")
SET(CPACK_PACKAGE_EXECUTABLES "ccmake" "CMake")
ENDIF(WIN32 AND NOT UNIX)
# cygwin specific packaging stuff
IF(CYGWIN)
SET(CPACK_PACKAGE_NAME cmake)
# setup the name of the package for cygwin cmake-2.4.3
SET(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
# the source has the same name as the binary
SET(CPACK_SOURCE_PACKAGE_FILE_NAME ${CPACK_PACKAGE_FILE_NAME})
# Create a cygwin version number in case there are changes for cygwin
# that are not reflected upstream in CMake
SET(CPACK_CYGWIN_PATCH_NUMBER 1)
# if we are on cygwin and have cpack, then force the
# doc, data and man dirs to conform to cygwin style directories
SET(CMAKE_DOC_DIR "/share/doc/${CPACK_PACKAGE_FILE_NAME}")
SET(CMAKE_DATA_DIR "/share/${CPACK_PACKAGE_FILE_NAME}")
SET(CMAKE_MAN_DIR "/share/man")
# let the user know we just forced these values
MESSAGE(STATUS "Setup for Cygwin packaging")
MESSAGE(STATUS "Override cache CMAKE_DOC_DIR = ${CMAKE_DOC_DIR}")
MESSAGE(STATUS "Override cache CMAKE_DATA_DIR = ${CMAKE_DATA_DIR}")
MESSAGE(STATUS "Override cache CMAKE_MAN_DIR = ${CMAKE_MAN_DIR}")
# These files are required by the cmCPackCygwinSourceGenerator and the files
# put into the release tar files.
SET(CPACK_CYGWIN_BUILD_SCRIPT
"${CMake_BINARY_DIR}/@CPACK_PACKAGE_FILE_NAME@-@CPACK_CYGWIN_PATCH_NUMBER@.sh")
SET(CPACK_CYGWIN_PATCH_FILE
"${CMake_BINARY_DIR}/@CPACK_PACKAGE_FILE_NAME@-@CPACK_CYGWIN_PATCH_NUMBER@.patch")
# include the sub directory for cygwin releases
SUBDIRS(Utilities/Release/Cygwin)
# when packaging source make sure the .build directory is not included
SET(CPACK_SOURCE_IGNORE_FILES
"/CVS/" "/\\\\.build/" "/\\\\.svn/" "\\\\.swp$" "\\\\.#" "/#" "~$")
ENDIF(CYGWIN)
# include CPack model once all variables are set
INCLUDE(CPack)
ENDIF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
# configure the CTestScript.cmake file into the binary directory
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/Templates/CTestScript.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/CTestScript.cmake"
@ONLY IMMEDIATE)
......
......@@ -99,6 +99,10 @@ IF(NOT CPACK_GENERATOR)
SET(CPACK_GENERATOR "STGZ;TGZ;TZ")
ENDIF(APPLE)
SET(CPACK_SOURCE_GENERATOR "TGZ;TZ")
IF(CYGWIN)
SET(CPACK_SOURCE_GENERATOR "CygwinSource")
SET(CPACK_GENERATOR "CygwinBinary")
ENDIF(CYGWIN)
ELSE(UNIX)
SET(CPACK_GENERATOR "NSIS;ZIP")
SET(CPACK_SOURCE_GENERATOR "ZIP")
......
......@@ -295,6 +295,8 @@ SET(CPACK_SRCS
CPack/cmCPackTarBZip2Generator.cxx
CPack/cmCPackTarCompressGenerator.cxx
CPack/cmCPackZIPGenerator.cxx
CPack/cmCPackCygwinBinaryGenerator.cxx
CPack/cmCPackCygwinSourceGenerator.cxx
)
# Build CPackLib
ADD_LIBRARY(CPackLib ${CPACK_SRCS})
......
......@@ -6,6 +6,7 @@ cmCPackGenerators -- creates cmCPackGenericGenerator's via NewGenerator
cmCPackGenericGenerator::Initialize
this->InitializeInternal
CPACK_INCLUDE_TOPLEVEL_DIRECTORY = 0 turns off
// binary package run
......@@ -64,3 +65,4 @@ break up cmCPackGenerator::InstallProject so it calls the following:
// run the cmake install scripts if provided
cmCPackGenerator::RunCMakeInstallScripts()
-
......@@ -41,7 +41,7 @@ cmCPackCygwinBinaryGenerator::~cmCPackCygwinBinaryGenerator()
//----------------------------------------------------------------------
int cmCPackCygwinBinaryGenerator::InitializeInternal()
{
this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1");
this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0");
std::vector<std::string> path;
std::string pkgPath = cmSystemTools::FindProgram("bzip2", path, false);
if ( pkgPath.empty() )
......@@ -62,13 +62,16 @@ int cmCPackCygwinBinaryGenerator::CompressFiles(const char* outFileName,
const char* toplevel, const std::vector<std::string>& files)
{
std::string packageName = this->GetOption("CPACK_PACKAGE_NAME");
packageName += "-";
packageName += this->GetOption("CPACK_PACKAGE_VERSION");
packageName = cmsys::SystemTools::LowerCase(packageName);
std::string manifest = "/share/doc/";
std::string manifest = "/usr/share/doc/";
manifest += packageName;
manifest += "/MANIFEST";
std::string manifestFile
= this->GetOption("CPACK_TEMPORARY_DIRECTORY");
// Create a MANIFEST file that contains all of the files in
// the tar file
std::string tempdir = manifestFile;
manifestFile += manifest;
// create an extra scope to force the stream
......@@ -78,18 +81,23 @@ int cmCPackCygwinBinaryGenerator::CompressFiles(const char* outFileName,
for(std::vector<std::string>::const_iterator i = files.begin();
i != files.end(); ++i)
{
#undef cerr
// remove the temp dir and replace with /usr
ofs << "/usr" << (*i).substr(tempdir.size()) << "\n";
std::cerr << "/usr" << (*i).substr(tempdir.size()) << "\n";
ofs << (*i).substr(tempdir.size()) << "\n";
}
ofs << "/usr" << manifest << "\n";
ofs << manifest << "\n";
}
// Now compress up everything
// add the manifest file to the list of all files
std::vector<std::string> filesWithManifest = files;
filesWithManifest.push_back(manifestFile);
// create the bzip2 tar file
return this->Superclass::CompressFiles(outFileName, toplevel,
filesWithManifest);
}
const char* cmCPackCygwinBinaryGenerator::GetOutputExtension()
{
this->OutputExtension = "-";
this->OutputExtension += this->GetOption("CPACK_CYGWIN_PATCH_NUMBER");
this->OutputExtension += ".tar.bz2";
return this->OutputExtension.c_str();
}
......@@ -33,12 +33,13 @@ public:
*/
cmCPackCygwinBinaryGenerator();
virtual ~cmCPackCygwinBinaryGenerator();
protected:
virtual const char* GetInstallPrefix() { return "/usr"; }
virtual int InitializeInternal();
int CompressFiles(const char* outFileName, const char* toplevel,
const std::vector<std::string>& files);
virtual const char* GetOutputExtension();
std::string OutputExtension;
};
#endif
......@@ -69,36 +69,29 @@ int cmCPackCygwinSourceGenerator::InitializeInternal()
int cmCPackCygwinSourceGenerator::CompressFiles(const char* outFileName,
const char* toplevel, const std::vector<std::string>& files)
{
// Create a tar file of the sources
std::string packageDirFileName
= this->GetOption("CPACK_TEMPORARY_DIRECTORY");
packageDirFileName += ".tar";
std::string output;
int retVal = -1;
if ( !this->Superclass::CompressFiles(packageDirFileName.c_str(),
// skip one parent up to the cmCPackTGZGenerator to create tar file
this->Compress = false; // just create tar not tar.gz
if ( !this->cmCPackTGZGenerator::CompressFiles(packageDirFileName.c_str(),
toplevel, files) )
{
return 0;
}
cmOStringStream dmgCmd1;
dmgCmd1 << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
<< "\" \"" << packageDirFileName
<< "\"";
retVal = -1;
int res = cmSystemTools::RunSingleCommand(dmgCmd1.str().c_str(), &output,
&retVal, toplevel, this->GeneratorVerbose, 0);
if ( !res || retVal )
{
std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
tmpFile += "/CompressBZip2.log";
cmGeneratedFileStream ofs(tmpFile.c_str());
ofs << "# Run command: " << dmgCmd1.str().c_str() << std::endl
<< "# Output:" << std::endl
<< output.c_str() << std::endl;
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running BZip2 command: "
<< dmgCmd1.str().c_str() << std::endl
<< "Please check " << tmpFile.c_str() << " for errors" << std::endl);
// Now bzip2 the source tar file
if(!this->BZip2File(packageDirFileName.c_str()))
{
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running BZip2 on file: "
<< packageDirFileName.c_str());
return 0;
}
// Now create a tar file that contains the above .tar.bz2 file
// and the CPACK_CYGWIN_PATCH_FILE and CPACK_TOPLEVEL_DIRECTORY
// files
std::string compressOutFile = packageDirFileName + ".bz2";
// at this point compressOutFile is the full path to
// _CPack_Package/.../package-2.5.0.tar.bz2
......@@ -108,7 +101,8 @@ int cmCPackCygwinSourceGenerator::CompressFiles(const char* outFileName,
// _CPack_Package/.../package-2.5.0-1.sh
// _CPack_Package/.../package-2.5.0.tar.bz2
// the -1 is CPACK_CYGWIN_PATCH_NUMBER
if(!cmSystemTools::CopyFileIfDifferent(
// copy the patch file into place
if(!cmSystemTools::CopyFileAlways(
this->GetOption("CPACK_CYGWIN_PATCH_FILE"),
this->GetOption("CPACK_TOPLEVEL_DIRECTORY")))
{
......@@ -117,7 +111,8 @@ int cmCPackCygwinSourceGenerator::CompressFiles(const char* outFileName,
<< this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "]\n");
return 0;
}
if(!cmSystemTools::CopyFileIfDifferent(
// copy the build script into place
if(!cmSystemTools::CopyFileAlways(
this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT"),
this->GetOption("CPACK_TOPLEVEL_DIRECTORY")))
{
......@@ -126,7 +121,7 @@ int cmCPackCygwinSourceGenerator::CompressFiles(const char* outFileName,
<< this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "]\n");
return 0;
}
// create the tar file
std::string outerTarFile
= this->GetOption("CPACK_TEMPORARY_DIRECTORY");
outerTarFile += "-";
......@@ -151,6 +146,7 @@ int cmCPackCygwinSourceGenerator::CompressFiles(const char* outFileName,
cmSystemTools::CreateTar(outerTarFile.c_str(),
outerFiles, false, false);
cmSystemTools::ChangeDirectory(saveDir.c_str());
// now compress the outer tar file
if(!this->BZip2File(outerTarFile.c_str()))
{
return 0;
......@@ -168,7 +164,6 @@ int cmCPackCygwinSourceGenerator::CompressFiles(const char* outFileName,
return 0;
}
}
return 1;
}
......
......@@ -26,7 +26,7 @@
class cmCPackCygwinSourceGenerator : public cmCPackTarBZip2Generator
{
public:
cmCPackTypeMacro(cmCPackCygwinSourceGenerator, cmCPackTGZGenerator);
cmCPackTypeMacro(cmCPackCygwinSourceGenerator, cmCPackTarBZip2Generator);
/**
* Construct generator
......
......@@ -31,6 +31,11 @@
# include "cmCPackOSXX11Generator.h"
#endif
#ifdef __CYGWIN__
# include "cmCPackCygwinBinaryGenerator.h"
# include "cmCPackCygwinSourceGenerator.h"
#endif
#include "cmCPackLog.h"
//----------------------------------------------------------------------
......@@ -44,6 +49,13 @@ cmCPackGenerators::cmCPackGenerators()
this->RegisterGenerator("NSIS", "Null Soft Installer",
cmCPackNSISGenerator::CreateGenerator);
#endif
#ifdef __CYGWIN__
this->RegisterGenerator("CygwinBinary", "Cygwin Binary Installer",
cmCPackCygwinBinaryGenerator::CreateGenerator);
this->RegisterGenerator("CygwinSource", "Cygwin Source Installer",
cmCPackCygwinSourceGenerator::CreateGenerator);
#endif
this->RegisterGenerator("ZIP", "ZIP file format",
cmCPackZIPGenerator::CreateGenerator);
this->RegisterGenerator("TBZ2", "Tar BZip2 compression",
......
......@@ -74,7 +74,6 @@ int cmCPackGenericGenerator::PrepareNames()
std::string outName = this->GetOption("CPACK_PACKAGE_FILE_NAME");
tempDirectory += "/" + outName;
outName += ".";
outName += this->GetOutputExtension();
std::string destFile = this->GetOption("CPACK_PACKAGE_DIRECTORY");
......@@ -82,7 +81,6 @@ int cmCPackGenericGenerator::PrepareNames()
std::string outFile = topDirectory + "/" + outName;
std::string installPrefix = tempDirectory + this->GetInstallPrefix();
this->SetOptionIfNotSet("CPACK_TOPLEVEL_DIRECTORY", topDirectory.c_str());
this->SetOptionIfNotSet("CPACK_TEMPORARY_DIRECTORY", tempDirectory.c_str());
this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_NAME", outName.c_str());
......@@ -106,7 +104,8 @@ int cmCPackGenericGenerator::PrepareNames()
if ( !cmSystemTools::FileExists(descFileName) )
{
cmCPackLogger(cmCPackLog::LOG_ERROR,
"Cannot find description file name: " << descFileName << std::endl);
"Cannot find description file name: ["
<< descFileName << "]" << std::endl);
return 0;
}
std::ifstream ifs(descFileName);
......@@ -235,6 +234,7 @@ int cmCPackGenericGenerator::InstallProject()
{
std::string fileName = tempInstallDirectory;
fileName += "/" + *it;
fileName += cmSystemTools::GetExecutableExtension();
cmCPackLogger(cmCPackLog::LOG_VERBOSE,
" Strip file: " << fileName.c_str()
<< std::endl);
......@@ -344,7 +344,8 @@ int cmCPackGenericGenerator::InstallProjectViaInstalledDirectories(
return 0;
}
std::vector<std::string>::iterator it;
const char* tempDir = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
const char* tempDir = tempInstallDirectory;
// this->GetOption("CPACK_TEMPORARY_DIRECTORY");
for ( it = installDirectoriesVector.begin();
it != installDirectoriesVector.end();
++it )
......
......@@ -94,7 +94,7 @@ protected:
int PrepareNames();
int InstallProject();
int CleanTemporaryDirectory();
virtual const char* GetOutputExtension() { return "cpack"; }
virtual const char* GetOutputExtension() { return ".cpack"; }
virtual const char* GetOutputPostfix() { return 0; }
virtual int CompressFiles(const char* outFileName, const char* toplevel,
const std::vector<std::string>& files);
......
......@@ -41,7 +41,7 @@ protected:
virtual int InitializeInternal();
int CompressFiles(const char* outFileName, const char* toplevel,
const std::vector<std::string>& files);
virtual const char* GetOutputExtension() { return "exe"; }
virtual const char* GetOutputExtension() { return ".exe"; }
virtual const char* GetOutputPostfix() { return "win32"; }
bool GetListOfSubdirectories(const char* dir,
......
......@@ -40,7 +40,7 @@ protected:
virtual int InitializeInternal();
int CompressFiles(const char* outFileName, const char* toplevel,
const std::vector<std::string>& files);
virtual const char* GetOutputExtension() { return "dmg"; }
virtual const char* GetOutputExtension() { return ".dmg"; }
virtual const char* GetInstallPrefix() { return ".app/Contents/Resources"; }
//bool CopyCreateResourceFile(const char* name, const char* dir);
......
......@@ -42,7 +42,7 @@ protected:
virtual int InitializeInternal();
int CompressFiles(const char* outFileName, const char* toplevel,
const std::vector<std::string>& files);
virtual const char* GetOutputExtension() { return "dmg"; }
virtual const char* GetOutputExtension() { return ".dmg"; }
virtual const char* GetOutputPostfix() { return "darwin"; }
virtual const char* GetInstallPrefix() { return "/usr"; }
......
......@@ -41,7 +41,7 @@ protected:
const std::vector<std::string>& files);
virtual int InitializeInternal();
int GenerateHeader(std::ostream* os);
virtual const char* GetOutputExtension() { return "sh"; }
virtual const char* GetOutputExtension() { return ".sh"; }
};
#endif
......@@ -44,7 +44,7 @@ protected:
virtual int GenerateHeader(std::ostream* os);
int CompressFiles(const char* outFileName, const char* toplevel,
const std::vector<std::string>& files);
virtual const char* GetOutputExtension() { return "tar.gz"; }
virtual const char* GetOutputExtension() { return ".tar.gz"; }
bool Compress;
};
......
......@@ -66,27 +66,17 @@ int cmCPackTarBZip2Generator::InitializeInternal()
}
//----------------------------------------------------------------------
int cmCPackTarBZip2Generator::CompressFiles(const char* outFileName,
const char* toplevel, const std::vector<std::string>& files)
int cmCPackTarBZip2Generator::BZip2File(const char* packageDirFileName)
{
std::string packageDirFileName
= this->GetOption("CPACK_TEMPORARY_DIRECTORY");
packageDirFileName += ".tar";
std::string output;
int retVal = -1;
if ( !this->Superclass::CompressFiles(packageDirFileName.c_str(),
toplevel, files) )
{
return 0;
}
int retVal = 0;
cmOStringStream dmgCmd1;
dmgCmd1 << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
<< "\" \"" << packageDirFileName
<< "\"";
retVal = -1;
std::string output;
int res = cmSystemTools::RunSingleCommand(dmgCmd1.str().c_str(), &output,
&retVal, toplevel, this->GeneratorVerbose, 0);
&retVal, 0, this->GeneratorVerbose, 0);
if ( !res || retVal )
{
std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
......@@ -100,7 +90,29 @@ int cmCPackTarBZip2Generator::CompressFiles(const char* outFileName,
<< "Please check " << tmpFile.c_str() << " for errors" << std::endl);
return 0;
}
return 1;
}
//----------------------------------------------------------------------
int cmCPackTarBZip2Generator::CompressFiles(const char* outFileName,
const char* toplevel, const std::vector<std::string>& files)
{
std::string packageDirFileName
= this->GetOption("CPACK_TEMPORARY_DIRECTORY");
packageDirFileName += ".tar";
std::string output;
int retVal = -1;
if ( !this->Superclass::CompressFiles(packageDirFileName.c_str(),
toplevel, files) )
{
return 0;
}
if(!this->BZip2File(packageDirFileName.c_str()))
{
return 0;
}
std::string compressOutFile = packageDirFileName + ".bz2";
if ( !cmSystemTools::SameFile(compressOutFile.c_str(), outFileName ) )
{
......
......@@ -39,8 +39,8 @@ protected:
virtual int InitializeInternal();
int CompressFiles(const char* outFileName, const char* toplevel,
const std::vector<std::string>& files);
virtual const char* GetOutputExtension() { return "tar.bz2"; }
virtual const char* GetOutputExtension() { return ".tar.bz2"; }
int BZip2File(const char* filename);
int RenameFile(const char* oldname, const char* newname);
};
......
......@@ -39,7 +39,7 @@ protected:
virtual int InitializeInternal();
int CompressFiles(const char* outFileName, const char* toplevel,
const std::vector<std::string>& files);
virtual const char* GetOutputExtension() { return "tar.Z"; }
virtual const char* GetOutputExtension() { return ".tar.Z"; }
int RenameFile(const char* oldname, const char* newname);
int GenerateHeader(std::ostream* os);
......
......@@ -48,7 +48,7 @@ protected:
virtual int InitializeInternal();
int CompressFiles(const char* outFileName, const char* toplevel,
const std::vector<std::string>& files);
virtual const char* GetOutputExtension() { return "zip"; }
virtual const char* GetOutputExtension() { return ".zip"; }
int ZipStyle;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment