CPack Archive Generator

CPack generator for packaging files into an archive, which can have any of the following formats:

  • 7Z - 7zip - (.7z) - LZMA compressed

    在 3.1 版被加入.

    This is an alias for 7Z_LZMA

  • 7Z_BZ2 - 7zip - (.7z) - BZip2 compressed

    在 4.3 版被加入.

  • 7Z_DEFLATE - 7zip - (.7z) - Deflate compressed

    在 4.3 版被加入.

  • 7Z_LZMA - 7zip - (.7z) - LZMA compressed

    在 4.3 版被加入.

  • 7Z_LZMA2 - 7zip - (.7z) - LZMA2 compressed

    在 4.3 版被加入.

  • 7Z_PPMD - 7zip - (.7z) - PPMd compressed

    在 4.3 版被加入.

  • 7Z_STORE - 7zip - (.7z) - no compression is used

    在 4.3 版被加入.

  • 7Z_ZSTD - 7zip - (.7z) - Zstandard compressed

    在 4.3 版被加入.

  • TAR (.tar) - no compression is used

    在 4.0 版被加入.

  • TBZ2 (.tar.bz2) - BZip2 compressed

  • TGZ (.tar.gz) - Deflate compressed

  • TXZ (.tar.xz) - LZMA2 compressed

    在 3.1 版被加入.

  • TZ (.tar.Z) - LZW compressed

  • TZST (.tar.zst) - Zstandard compressed

    在 3.16 版被加入.

  • ZIP (.zip) - Deflate compressed

    This is an alias for ZIP_DEFLATE

  • ZIP_BZ2 (.zip) - BZip2 compressed

    在 4.3 版被加入.

  • ZIP_DEFLATE (.zip) - Deflate compressed

    在 4.3 版被加入.

  • ZIP_LZMA (.zip) - LZMA compressed

    在 4.3 版被加入.

  • ZIP_LZMA2 (.zip) - LZMA2 compressed

    在 4.3 版被加入.

  • ZIP_STORE (.zip) - no compression is used

    在 4.3 版被加入.

  • ZIP_ZSTD (.zip) - Zstandard compressed

    在 4.3 版被加入.

When this generator is called from CPackSourceConfig.cmake (or through the package_source target), then the generated archive will contain all files in the project directory, except those specified in CPACK_SOURCE_IGNORE_FILES. The following is one example of packaging all source files of a project:

set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_SOURCE_IGNORE_FILES
  \\.git/
  build/
  ".*~$"
)
set(CPACK_VERBATIM_VARIABLES YES)
include(CPack)

When this generator is called from CPackConfig.cmake (or through the package target), then the generated archive will contain all files that have been installed via CMake's install() command (and the deprecated commands install_files(), install_programs(), and install_targets()).

Variables specific to CPack Archive generator

CPACK_ARCHIVE_FILE_NAME

在 3.9 版被加入.

Archive name for component-based packages, without extension.

Default:

CPACK_PACKAGE_FILE_NAME

The extension is appended automatically.

If CPACK_COMPONENTS_GROUPING is set to ALL_COMPONENTS_IN_ONE, this will be the name of the one output archive.

在 4.0 版的變更: This variable also works for non-component packages.

CPACK_ARCHIVE_<component>_FILE_NAME

在 3.9 版被加入.

Component archive name without extension.

Default:

<CPACK_ARCHIVE_FILE_NAME>-<component>, with spaces replaced by '-'.

The extension is appended automatically. Note that <component> is all uppercase in the variable name.

CPACK_ARCHIVE_FILE_EXTENSION

在 3.25 版被加入.

Archive file extension.

Default:

Default values are given in the list above.

CPACK_ARCHIVE_COMPONENT_INSTALL

Enable component packaging.

Default:

OFF

If enabled (ON) multiple packages are generated. By default a single package containing files of all components is generated.

CPACK_ARCHIVE_UID

Set the UID of entries contained in the archive. Specify -1 to use the UID of the current user.

Default:

0 (see policy CMP0206)

CPACK_ARCHIVE_GID

Set the GID of entries contained in the archive. Specify -1 to use the GID of the current user.

Default:

0 (see policy CMP0206)

Variables used by CPack Archive generator

These variables are used by the Archive generator, but are also available to CPack generators which are essentially archives at their core. These include:

CPACK_ARCHIVE_THREADS

在 3.18 版被加入.

The number of threads to use when performing the compression.

Default:

value of CPACK_THREADS

If set to 0, the number of available cores on the machine will be used instead. Note that not all compression modes support threading in all environments.

在 3.21 版被加入: Official CMake binaries available on cmake.org now ship with a liblzma that supports parallel compression. Older versions did not.

CPACK_ARCHIVE_COMPRESSION_LEVEL

在 4.3 版被加入.

The compression level to use when compressing the archive.

Default:

value of CPACK_COMPRESSION_LEVEL

The compression level should be between 0 and 9.

The compression level of the Zstandard-based algorithm can be set between 0 and 19, except for the ZIP_ZSTD mode.

The value 0 is used to specify the default compression level. It is selected automatically by the archive library backend and not directly set by CMake itself. The default compression level may vary between archive formats, platforms, etc.