CPackDeb: Add option to set compression type

Add a CPACK_DEBIAN_COMPRESSION_TYPE option to set the compression type.
Default to 'gzip' to preserve existing behavior.  Use "cmake -E tar"
for 'gzip', 'bzip2', and 'none'.  Use system "tar" for 'lzma' and 'xz'.
This commit is contained in:
Sean D'Epagnier 2014-03-10 13:37:26 +08:00 committed by Brad King
parent 82a7d54cfe
commit 13778cd3be
2 changed files with 49 additions and 10 deletions

View File

@ -67,7 +67,12 @@
# * Mandatory : YES # * Mandatory : YES
# * Default : 'devel' # * Default : 'devel'
# #
# The debian package section # .. variable:: CPACK_DEBIAN_COMPRESSION_TYPE
#
# * Mandatory : YES
# * Default : 'gzip'
#
# Possible values are: lzma, xz, bzip2 and gzip.
# #
# .. variable:: CPACK_DEBIAN_PACKAGE_PRIORITY # .. variable:: CPACK_DEBIAN_PACKAGE_PRIORITY
# #
@ -390,6 +395,12 @@ if(NOT CPACK_DEBIAN_PACKAGE_PRIORITY)
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
endif() endif()
# Compression: (recommended)
if(NOT CPACK_DEBIAN_COMPRESSION_TYPE)
set(CPACK_DEBIAN_COMPRESSION_TYPE "gzip")
endif()
# Recommends: # Recommends:
# You should set: CPACK_DEBIAN_PACKAGE_RECOMMENDS # You should set: CPACK_DEBIAN_PACKAGE_RECOMMENDS

View File

@ -403,9 +403,39 @@ int cmCPackDebGenerator::createDeb()
if (NULL != this->GetOption("CPACK_DEBIAN_FAKEROOT_EXECUTABLE")) { if (NULL != this->GetOption("CPACK_DEBIAN_FAKEROOT_EXECUTABLE")) {
cmd += this->GetOption("CPACK_DEBIAN_FAKEROOT_EXECUTABLE"); cmd += this->GetOption("CPACK_DEBIAN_FAKEROOT_EXECUTABLE");
} }
cmd += " \"";
cmd += cmakeExecutable; const char* debian_compression_type =
cmd += "\" -E tar cfz data.tar.gz "; this->GetOption("CPACK_DEBIAN_COMPRESSION_TYPE");
if(!debian_compression_type)
{
debian_compression_type = "gzip";
}
std::string cmake_tar = " ", compression_modifier = "a", compression_suffix;
if(!strcmp(debian_compression_type, "lzma")) {
compression_suffix = ".lzma";
} else if(!strcmp(debian_compression_type, "xz")) {
compression_suffix = ".xz";
} else if(!strcmp(debian_compression_type, "bzip2")) {
compression_suffix = ".bz2";
compression_modifier = "j";
cmake_tar += "\"" + std::string(cmakeExecutable) + "\" -E ";
} else if(!strcmp(debian_compression_type, "gzip")) {
compression_suffix = ".gz";
compression_modifier = "z";
cmake_tar += "\"" + std::string(cmakeExecutable) + "\" -E ";
} else if(!strcmp(debian_compression_type, "none")) {
compression_suffix = "";
compression_modifier = "";
cmake_tar += "\"" + std::string(cmakeExecutable) + "\" -E ";
} else {
cmCPackLogger(cmCPackLog::LOG_ERROR,
"Error unrecognized compression type: "
<< debian_compression_type << std::endl);
}
cmd += cmake_tar + "tar c" + compression_modifier + "f data.tar"
+ compression_suffix;
// now add all directories which have to be compressed // now add all directories which have to be compressed
// collect all top level install dirs for that // collect all top level install dirs for that
@ -493,9 +523,7 @@ int cmCPackDebGenerator::createDeb()
{ {
cmd = this->GetOption("CPACK_DEBIAN_FAKEROOT_EXECUTABLE"); cmd = this->GetOption("CPACK_DEBIAN_FAKEROOT_EXECUTABLE");
} }
cmd += " \""; cmd += cmake_tar + "tar czf control.tar.gz ./control ./md5sums";
cmd += cmakeExecutable;
cmd += "\" -E tar cfz control.tar.gz ./control ./md5sums";
const char* controlExtra = const char* controlExtra =
this->GetOption("CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA"); this->GetOption("CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA");
if( controlExtra ) if( controlExtra )
@ -514,7 +542,7 @@ int cmCPackDebGenerator::createDeb()
if( cmsys::SystemTools::CopyFileIfDifferent( if( cmsys::SystemTools::CopyFileIfDifferent(
i->c_str(), localcopy.c_str()) ) i->c_str(), localcopy.c_str()) )
{ {
// debian is picky and need relative to ./ path in the tar.gz // debian is picky and need relative to ./ path in the tar.*
cmd += " ./"; cmd += " ./";
cmd += filenamename; cmd += filenamename;
} }
@ -538,7 +566,7 @@ int cmCPackDebGenerator::createDeb()
return 0; return 0;
} }
// ar -r your-package-name.deb debian-binary control.tar.gz data.tar.gz // ar -r your-package-name.deb debian-binary control.tar.* data.tar.*
// since debian packages require BSD ar (most Linux distros and even // since debian packages require BSD ar (most Linux distros and even
// FreeBSD and NetBSD ship GNU ar) we use a copy of OpenBSD ar here. // FreeBSD and NetBSD ship GNU ar) we use a copy of OpenBSD ar here.
std::vector<std::string> arFiles; std::vector<std::string> arFiles;
@ -546,7 +574,7 @@ int cmCPackDebGenerator::createDeb()
topLevelString += "/"; topLevelString += "/";
arFiles.push_back(topLevelString + "debian-binary"); arFiles.push_back(topLevelString + "debian-binary");
arFiles.push_back(topLevelString + "control.tar.gz"); arFiles.push_back(topLevelString + "control.tar.gz");
arFiles.push_back(topLevelString + "data.tar.gz"); arFiles.push_back(topLevelString + "data.tar" + compression_suffix);
std::string outputFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); std::string outputFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
outputFileName += "/"; outputFileName += "/";
outputFileName += this->GetOption("CPACK_OUTPUT_FILE_NAME"); outputFileName += this->GetOption("CPACK_OUTPUT_FILE_NAME");