Compression level when creating archives

Hi,

CMake 3.19 added a COMPRESSION_LEVEL option to the file(ARCHIVE_CREATE) command. Would it be possible to add a flag for setting the compression level to the built-in tar command (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 a compression-level option for zip and 7zip as well.

Thanks :slightly_smiling_face:

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).

Probably an oversight. Please file an issue.

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

Done: #22498