mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-01-26 19:09:06 +00:00
CPack/DEB: Add CPACK_DEBIAN_COMPRESSION_LEVEL variable
Add a new variable `CPACK_DEBIAN_COMPRESSION_LEVEL` to control the compression level used when generating Debian packages. This complements the existing `CPACK_DEBIAN_COMPRESSION_TYPE` variable and allows finer control over the compression performance vs. size trade-off. Supported values correspond to the compression level accepted by the underlying compressor (e.g. gzip, xz, zstd, etc.).
This commit is contained in:
parent
70dcdffb1f
commit
07fe3f95ce
@ -306,6 +306,37 @@ List of CPack DEB generator specific variables:
|
||||
|
||||
Zstandard compression
|
||||
|
||||
.. variable:: CPACK_DEBIAN_COMPRESSION_LEVEL
|
||||
|
||||
.. versionadded:: 4.3
|
||||
|
||||
The compression level used for creating the Debian package.
|
||||
|
||||
:Mandatory: No
|
||||
:Default: Automatically determined by the compression tool.
|
||||
|
||||
This variable allows fine-tuning of the compression ratio and speed for the
|
||||
Debian package archive. It controls the numeric compression level passed to
|
||||
the compressor defined by :variable:`CPACK_DEBIAN_COMPRESSION_TYPE`.
|
||||
If ``CPACK_DEBIAN_COMPRESSION_LEVEL`` is not set, or is set to ``0``,
|
||||
the default value will be used.
|
||||
|
||||
The valid range and interpretation depend on the selected compression type:
|
||||
|
||||
- ``gzip`` – level 1–9 (default 6)
|
||||
- ``bzip2`` – level 1–9 (default 9)
|
||||
- ``xz`` – level 1–9 (default 6)
|
||||
- ``lzma`` – level 1–9 (default 6)
|
||||
- ``zstd`` – level 1–19 (default 3)
|
||||
|
||||
Example usage:
|
||||
|
||||
.. code-block:: cmake
|
||||
|
||||
set(CPACK_DEBIAN_COMPRESSION_TYPE "xz")
|
||||
set(CPACK_DEBIAN_COMPRESSION_LEVEL 9)
|
||||
|
||||
include(CPack)
|
||||
|
||||
.. variable:: CPACK_DEBIAN_PACKAGE_PRIORITY
|
||||
CPACK_DEBIAN_<COMPONENT>_PACKAGE_PRIORITY
|
||||
|
||||
6
Help/release/dev/cpack-deb-compression-level.rst
Normal file
6
Help/release/dev/cpack-deb-compression-level.rst
Normal file
@ -0,0 +1,6 @@
|
||||
cpack-deb-compression-level
|
||||
---------------------------
|
||||
|
||||
* The :cpack_gen:`CPack DEB Generator` gained a new variable
|
||||
:variable:`CPACK_DEBIAN_COMPRESSION_LEVEL` to control the
|
||||
compression level used when creating Debian packages.
|
||||
@ -808,6 +808,10 @@ function(cpack_deb_prepare_package_vars)
|
||||
string(REGEX REPLACE "\.deb$" "-dbgsym.ddeb" CPACK_DBGSYM_OUTPUT_FILE_NAME "${CPACK_OUTPUT_FILE_NAME}")
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED CPACK_DEBIAN_COMPRESSION_LEVEL)
|
||||
set(CPACK_DEBIAN_COMPRESSION_LEVEL "0")
|
||||
endif()
|
||||
|
||||
# Print out some debug information if we were asked for that
|
||||
if(CPACK_DEBIAN_PACKAGE_DEBUG)
|
||||
message("CPackDeb:Debug: CPACK_TOPLEVEL_DIRECTORY = '${CPACK_TOPLEVEL_DIRECTORY}'")
|
||||
@ -820,6 +824,7 @@ function(cpack_deb_prepare_package_vars)
|
||||
message("CPackDeb:Debug: CPACK_TEMPORARY_PACKAGE_FILE_NAME = '${CPACK_TEMPORARY_PACKAGE_FILE_NAME}'")
|
||||
message("CPackDeb:Debug: CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION = '${CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION}'")
|
||||
message("CPackDeb:Debug: CPACK_DEBIAN_PACKAGE_SOURCE = '${CPACK_DEBIAN_PACKAGE_SOURCE}'")
|
||||
message("CPackDeb:Debug: CPACK_DEBIAN_COMPRESSION_LEVEL = '${CPACK_DEBIAN_COMPRESSION_LEVEL}'")
|
||||
endif()
|
||||
|
||||
# For debian source packages:
|
||||
@ -849,6 +854,7 @@ function(cpack_deb_prepare_package_vars)
|
||||
set(GEN_CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE)
|
||||
set(GEN_CPACK_DEBIAN_ARCHIVE_TYPE "${CPACK_DEBIAN_ARCHIVE_TYPE}" PARENT_SCOPE)
|
||||
set(GEN_CPACK_DEBIAN_COMPRESSION_TYPE "${CPACK_DEBIAN_COMPRESSION_TYPE}" PARENT_SCOPE)
|
||||
set(GEN_CPACK_DEBIAN_COMPRESSION_LEVEL "${CPACK_DEBIAN_COMPRESSION_LEVEL}" PARENT_SCOPE)
|
||||
set(GEN_CPACK_DEBIAN_PACKAGE_RECOMMENDS "${CPACK_DEBIAN_PACKAGE_RECOMMENDS}" PARENT_SCOPE)
|
||||
set(GEN_CPACK_DEBIAN_PACKAGE_SUGGESTS "${CPACK_DEBIAN_PACKAGE_SUGGESTS}" PARENT_SCOPE)
|
||||
set(GEN_CPACK_DEBIAN_PACKAGE_HOMEPAGE "${CPACK_DEBIAN_PACKAGE_HOMEPAGE}" PARENT_SCOPE)
|
||||
|
||||
@ -32,8 +32,8 @@ class DebGenerator
|
||||
public:
|
||||
DebGenerator(cmCPackLog* logger, std::string outputName, std::string workDir,
|
||||
std::string topLevelDir, std::string temporaryDir,
|
||||
cmValue debianCompressionType, cmValue numThreads,
|
||||
cmValue debianArchiveType,
|
||||
cmValue debianCompressionType, cmValue debianCompressionLevel,
|
||||
cmValue numThreads, cmValue debianArchiveType,
|
||||
std::map<std::string, std::string> controlValues,
|
||||
bool genShLibs, std::string shLibsFilename, bool genPostInst,
|
||||
std::string postInst, bool genPostRm, std::string postRm,
|
||||
@ -69,16 +69,18 @@ private:
|
||||
bool const PermissionStrictPolicy;
|
||||
std::vector<std::string> const PackageFiles;
|
||||
cmArchiveWrite::Compress TarCompressionType;
|
||||
int CompressionLevel = 0;
|
||||
};
|
||||
|
||||
DebGenerator::DebGenerator(
|
||||
cmCPackLog* logger, std::string outputName, std::string workDir,
|
||||
std::string topLevelDir, std::string temporaryDir,
|
||||
cmValue debCompressionType, cmValue numThreads, cmValue debianArchiveType,
|
||||
std::map<std::string, std::string> controlValues, bool genShLibs,
|
||||
std::string shLibsFilename, bool genPostInst, std::string postInst,
|
||||
bool genPostRm, std::string postRm, cmValue controlExtra,
|
||||
bool permissionStrictPolicy, std::vector<std::string> packageFiles)
|
||||
cmValue debCompressionType, cmValue debCompressionLevel, cmValue numThreads,
|
||||
cmValue debianArchiveType, std::map<std::string, std::string> controlValues,
|
||||
bool genShLibs, std::string shLibsFilename, bool genPostInst,
|
||||
std::string postInst, bool genPostRm, std::string postRm,
|
||||
cmValue controlExtra, bool permissionStrictPolicy,
|
||||
std::vector<std::string> packageFiles)
|
||||
: Logger(logger)
|
||||
, OutputName(std::move(outputName))
|
||||
, WorkDir(std::move(workDir))
|
||||
@ -135,6 +137,19 @@ DebGenerator::DebGenerator(
|
||||
} else {
|
||||
this->NumThreads = 1;
|
||||
}
|
||||
|
||||
if (debCompressionLevel) {
|
||||
long compressionLevel;
|
||||
if (!cmStrToLong(*debCompressionLevel, &compressionLevel)) {
|
||||
compressionLevel = 0;
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
||||
"Unrecognized compression level: " << debCompressionLevel
|
||||
<< std::endl);
|
||||
}
|
||||
this->CompressionLevel = static_cast<int>(compressionLevel);
|
||||
} else {
|
||||
this->CompressionLevel = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool DebGenerator::generate() const
|
||||
@ -192,7 +207,7 @@ bool DebGenerator::generateDataTar() const
|
||||
return false;
|
||||
}
|
||||
cmArchiveWrite data_tar(fileStream_data_tar, this->TarCompressionType,
|
||||
this->DebianArchiveType, 0,
|
||||
this->DebianArchiveType, this->CompressionLevel,
|
||||
static_cast<int>(this->NumThreads));
|
||||
if (!data_tar.Open()) {
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
||||
@ -324,7 +339,7 @@ bool DebGenerator::generateControlTar(std::string const& md5Filename) const
|
||||
return false;
|
||||
}
|
||||
cmArchiveWrite control_tar(fileStream_control_tar, this->TarCompressionType,
|
||||
this->DebianArchiveType);
|
||||
this->DebianArchiveType, this->CompressionLevel);
|
||||
if (!control_tar.Open()) {
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
||||
"Error opening the archive \""
|
||||
@ -846,6 +861,7 @@ bool cmCPackDebGenerator::createDeb()
|
||||
this->GetOption("CPACK_TOPLEVEL_DIRECTORY"),
|
||||
this->GetOption("CPACK_TEMPORARY_DIRECTORY"),
|
||||
this->GetOption("GEN_CPACK_DEBIAN_COMPRESSION_TYPE"),
|
||||
this->GetOption("GEN_CPACK_DEBIAN_COMPRESSION_LEVEL"),
|
||||
this->GetOption("CPACK_THREADS"),
|
||||
this->GetOption("GEN_CPACK_DEBIAN_ARCHIVE_TYPE"), controlValues, gen_shibs,
|
||||
shlibsfilename, this->IsOn("GEN_CPACK_DEBIAN_GENERATE_POSTINST"), postinst,
|
||||
@ -901,6 +917,7 @@ bool cmCPackDebGenerator::createDbgsymDDeb()
|
||||
this->GetOption("CPACK_TOPLEVEL_DIRECTORY"),
|
||||
this->GetOption("CPACK_TEMPORARY_DIRECTORY"),
|
||||
this->GetOption("GEN_CPACK_DEBIAN_COMPRESSION_TYPE"),
|
||||
this->GetOption("GEN_CPACK_DEBIAN_COMPRESSION_LEVEL"),
|
||||
this->GetOption("CPACK_THREADS"),
|
||||
this->GetOption("GEN_CPACK_DEBIAN_ARCHIVE_TYPE"), controlValues, false, "",
|
||||
false, "", false, "", nullptr,
|
||||
|
||||
@ -11,4 +11,8 @@ d[rwx-]+ root/root 0 [0-9-]+ [0-9:]+ \./usr/share/
|
||||
d[rwx-]+ root/root 0 [0-9-]+ [0-9:]+ \./usr/share/doc/
|
||||
d[rwx-]+ root/root 0 [0-9-]+ [0-9:]+ \./usr/share/doc/basic/
|
||||
-[rwx-]+ root/root 0 [0-9-]+ [0-9:]+ \./usr/share/doc/basic/basic\.txt
|
||||
-- ar t
|
||||
debian-binary
|
||||
control\.tar\.xz
|
||||
data\.tar\.xz
|
||||
--
|
||||
|
||||
@ -2,3 +2,5 @@ message(STATUS "dpkg-deb --info")
|
||||
execute_process(COMMAND dpkg-deb --info ${CMAKE_ARGV4})
|
||||
message(STATUS "dpkg-deb --contents")
|
||||
execute_process(COMMAND dpkg-deb --contents ${CMAKE_ARGV4})
|
||||
message(STATUS "ar t")
|
||||
execute_process(COMMAND ar t ${CMAKE_ARGV4})
|
||||
|
||||
@ -3,5 +3,8 @@ project(Basic LANGUAGES NONE VERSION "1.2.3")
|
||||
|
||||
install(FILES basic.txt DESTINATION share/doc/basic)
|
||||
|
||||
set(CPACK_DEBIAN_COMPRESSION_TYPE "xz")
|
||||
set(CPACK_DEBIAN_COMPRESSION_LEVEL "4")
|
||||
|
||||
set(CPACK_PACKAGE_CONTACT "somebody@cmake.org")
|
||||
include(CPack)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user