# Compression level when creating archives

**URL:** https://discourse.cmake.org/t/compression-level-when-creating-archives/3851
**Category:** Development
**Created:** [July 29, 2021, 12:45pm UTC](https://discourse.cmake.org/t/compression-level-when-creating-archives/3851 "2021-07-29T12:45:02Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![petwu](https://discourse.cmake.org/user_avatar/discourse.cmake.org/petwu/32/1399_2.png) [@petwu](https://discourse.cmake.org/u/petwu)
#### Post date: [July 29, 2021, 12:45pm UTC](https://discourse.cmake.org/t/compression-level-when-creating-archives/3851/1 "2021-07-29T12:45:03Z")

</div>

Hi,

CMake 3.19 added a `COMPRESSION_LEVEL` option to the [file(ARCHIVE\_CREATE)](https://cmake.org/cmake/help/latest/command/file.html#archiving) command. Would it be possible to add a flag for setting the compression level to the built-in [tar command](https://cmake.org/cmake/help/latest/manual/cmake.1.html#run-a-command-line-tool) (`cmake -E tar ...`) as well? I suppose the implementation is already there, you would just need to extend the command line interface? This would be great so that one could use the compression level feature in custom commands/targets as well, e.g. to zip some output files in a post-build step. I would suggest to have the flag (or flags) be named `-0`, `-1`, …, `-9` to conform to command line tools like zip, gzip, xz, etc.

Also, is there a reason, why the `COMPRESSION_LEVEL` option can only be set when `COMPRESSION` is set too? I get that the `zip` and `7zip` formats already imply a specific compression algorithm so it makes no sense to set the `COMPRESSION` option with either of them, but as far as I know those formats support different compression levels as well. At least _libarchive_ that CMake uses [seems to support](https://www.freebsd.org/cgi/man.cgi?query=archive_write_set_options&sektion=3&format=html) a `compression-level` option for `zip` and `7zip` as well.

Thanks 🙂

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [July 29, 2021, 3:00pm UTC](https://discourse.cmake.org/t/compression-level-when-creating-archives/3851/2 "2021-07-29T15:00:45Z")

</div>

> [@petwu](#):
>
> I would suggest to have the flag (or flags) be named `-0`, `-1`, …, `-9` to conform to command line tools like zip, gzip, xz, etc.

`cmake -E tar` tries to map onto `tar`, not these tools. `tar` itself has no compression flag, so I would think that `--compression` would be better (alas, there’s probably not an available single letter short name for it that isn’t totally obtuse like `-e` or something).

> [@petwu](#):
>
> Also, is there a reason, why the `COMPRESSION_LEVEL` option can only be set when `COMPRESSION` is set too? I get that the `zip` and `7zip` formats already imply a specific compression algorithm so it makes no sense to set the `COMPRESSION` option with either of them

Probably an oversight. Please file an issue.

---

<div class="post-metadata">

### Author: ![petwu](https://discourse.cmake.org/user_avatar/discourse.cmake.org/petwu/32/1399_2.png) [@petwu](https://discourse.cmake.org/u/petwu)
#### Post date: [July 30, 2021, 6:02am UTC](https://discourse.cmake.org/t/compression-level-when-creating-archives/3851/3 "2021-07-30T06:02:40Z")

</div>

> [@ben.boeckel](#):
>
> so I would think that `--compression` would be better

I would be fine with `--compression` or `--compression-level` too.

---

<div class="post-metadata">

### Author: ![petwu](https://discourse.cmake.org/user_avatar/discourse.cmake.org/petwu/32/1399_2.png) [@petwu](https://discourse.cmake.org/u/petwu)
#### Post date: [July 30, 2021, 6:25am UTC](https://discourse.cmake.org/t/compression-level-when-creating-archives/3851/4 "2021-07-30T06:25:04Z")

</div>

> [@ben.boeckel](#):
>
> Please file an issue.

Done: [#22498](https://gitlab.kitware.com/cmake/cmake/-/issues/22498)
