diff options
author | Asit Dhal <dhal.asitk@gmail.com> | 2020-09-17 17:29:31 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-09-21 17:08:11 (GMT) |
commit | 195d14e7818244789638fffd2087b8b2d0952622 (patch) | |
tree | 7e46f8f1f6dfbb60dc73bb600e1190369bc00bc0 /Source/cmArchiveWrite.cxx | |
parent | 4fc07cd369cd46fbd859f140eda971d00ac52704 (diff) | |
download | CMake-195d14e7818244789638fffd2087b8b2d0952622.zip CMake-195d14e7818244789638fffd2087b8b2d0952622.tar.gz CMake-195d14e7818244789638fffd2087b8b2d0952622.tar.bz2 |
file(ARCHIVE_CREATE): Add option to control compression level
Fixes: #21125
Diffstat (limited to 'Source/cmArchiveWrite.cxx')
-rw-r--r-- | Source/cmArchiveWrite.cxx | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx index addfbff..356089b 100644 --- a/Source/cmArchiveWrite.cxx +++ b/Source/cmArchiveWrite.cxx @@ -81,7 +81,7 @@ struct cmArchiveWrite::Callback }; cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, - std::string const& format) + std::string const& format, int compressionLevel) : Stream(os) , Archive(archive_write_new()) , Disk(archive_read_disk_new()) @@ -151,6 +151,41 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, } break; } + + if (compressionLevel != 0) { + std::string compressionLevelStr = std::to_string(compressionLevel); + std::string archiveFilterName; + switch (c) { + case CompressNone: + case CompressCompress: + break; + case CompressGZip: + archiveFilterName = "gzip"; + break; + case CompressBZip2: + archiveFilterName = "bzip2"; + break; + case CompressLZMA: + archiveFilterName = "lzma"; + break; + case CompressXZ: + archiveFilterName = "xz"; + break; + case CompressZstd: + archiveFilterName = "zstd"; + break; + } + if (!archiveFilterName.empty()) { + if (archive_write_set_filter_option( + this->Archive, archiveFilterName.c_str(), "compression-level", + compressionLevelStr.c_str()) != ARCHIVE_OK) { + this->Error = cmStrCat("archive_write_set_filter_option: ", + cm_archive_error_string(this->Archive)); + return; + } + } + } + #if !defined(_WIN32) || defined(__CYGWIN__) if (archive_read_disk_set_standard_lookup(this->Disk) != ARCHIVE_OK) { this->Error = cmStrCat("archive_read_disk_set_standard_lookup: ", |