CPack¶
Configure generators for binary installers and source packages.
Introduction¶
The CPack module generates the configuration files CPackConfig.cmake
and CPackSourceConfig.cmake
. They are intended for use in a subsequent
run of the cpack
program where they steer the generation
of installers or/and source packages.
Depending on the CMake generator, the CPack module may also add two new build
targets, package
and package_source
. See the packaging targets
section below for details.
The generated binary installers will contain all files that have been installed
via CMake's install()
command (and the deprecated commands
install_files()
, install_programs()
, and
install_targets()
). Note that the DESTINATION
option of the
install()
command must be a relative path; otherwise installed files
are ignored by CPack.
Certain kinds of binary installers can be configured such that users can select
individual application components to install. See the CPackComponent
module for further details.
Source packages (configured through CPackSourceConfig.cmake
and generated
by the CPack Archive Generator
) will contain all source files in
the project directory except those specified in
CPACK_SOURCE_IGNORE_FILES
.
CPack Generators¶
The CPACK_GENERATOR
variable has different meanings in different
contexts. In a CMakeLists.txt
file, CPACK_GENERATOR
is a
list of generators: and when cpack
is run with no other
arguments, it will iterate over that list and produce one package for each
generator. In a CPACK_PROJECT_CONFIG_FILE
,
CPACK_GENERATOR
is a string naming a single generator. If you
need per-cpack-generator logic to control other cpack settings, then you
need a CPACK_PROJECT_CONFIG_FILE
.
If set, the CPACK_PROJECT_CONFIG_FILE
is included automatically
on a per-generator basis. It only need contain overrides.
Here's how it works:
cpack
runsit includes
CPackConfig.cmake
it iterates over the generators given by the
-G
command line option, or if no such option was specified, over the list of generators given by theCPACK_GENERATOR
variable set in theCPackConfig.cmake
input file.foreach generator, it then
sets
CPACK_GENERATOR
to the one currently being iteratedincludes the
CPACK_PROJECT_CONFIG_FILE
produces the package for that generator
This is the key: For each generator listed in CPACK_GENERATOR
in
CPackConfig.cmake
, cpack will reset CPACK_GENERATOR
internally to the one currently being used and then include the
CPACK_PROJECT_CONFIG_FILE
.
For a list of available generators, see cpack-generators(7)
.
Targets package and package_source¶
If CMake is run with the Makefile, Ninja, or Xcode generator, then
include(CPack)
generates a target package
. This makes it possible
to build a binary installer from CMake, Make, or Ninja: Instead of cpack
,
one may call cmake --build . --target package
or make package
or
ninja package
. The VS generator creates an uppercase target PACKAGE
.
If CMake is run with the Makefile or Ninja generator, then include(CPack)
also generates a target package_source
. To build a source package,
instead of cpack -G TGZ --config CPackSourceConfig.cmake
one may call
cmake --build . --target package_source
, make package_source
,
or ninja package_source
.
Variables common to all CPack Generators¶
Before including this CPack module in your CMakeLists.txt
file, there
are a variety of variables that can be set to customize the resulting
installers. The most commonly-used variables are:
- CPACK_PACKAGE_NAME¶
The name of the package (or application). If not specified, it defaults to the project name.
- CPACK_PACKAGE_VENDOR¶
The name of the package vendor. (e.g., "Kitware"). The default is "Humanity".
- CPACK_PACKAGE_DIRECTORY¶
The directory in which CPack is doing its packaging. If it is not set then this will default (internally) to the build dir. This variable may be defined in a CPack config file or from the
cpack
command line option-B
. If set, the command line option overrides the value found in the config file.
- CPACK_PACKAGE_VERSION_MAJOR¶
Package major version. This variable will always be set, but its default value depends on whether or not version details were given to the
project()
command in the top level CMakeLists.txt file. If version details were given, the default value will beCMAKE_PROJECT_VERSION_MAJOR
. If no version details were given, a default version of 0.1.1 will be assumed, leading toCPACK_PACKAGE_VERSION_MAJOR
having a default value of 0.
- CPACK_PACKAGE_VERSION_MINOR¶
Package minor version. The default value is determined based on whether or not version details were given to the
project()
command in the top level CMakeLists.txt file. If version details were given, the default value will beCMAKE_PROJECT_VERSION_MINOR
, but if no minor version component was specified thenCPACK_PACKAGE_VERSION_MINOR
will be left unset. If no project version was given at all, a default version of 0.1.1 will be assumed, leading toCPACK_PACKAGE_VERSION_MINOR
having a default value of 1.
- CPACK_PACKAGE_VERSION_PATCH¶
Package patch version. The default value is determined based on whether or not version details were given to the
project()
command in the top level CMakeLists.txt file. If version details were given, the default value will beCMAKE_PROJECT_VERSION_PATCH
, but if no patch version component was specified thenCPACK_PACKAGE_VERSION_PATCH
will be left unset. If no project version was given at all, a default version of 0.1.1 will be assumed, leading toCPACK_PACKAGE_VERSION_PATCH
having a default value of 1.
- CPACK_PACKAGE_DESCRIPTION¶
A description of the project, used in places such as the introduction screen of CPack-generated Windows installers. If not set, the value of this variable is populated from the file named by
CPACK_PACKAGE_DESCRIPTION_FILE
.
- CPACK_PACKAGE_DESCRIPTION_FILE¶
A text file used to describe the project when
CPACK_PACKAGE_DESCRIPTION
is not explicitly set. The default value forCPACK_PACKAGE_DESCRIPTION_FILE
points to a built-in template fileTemplates/CPack.GenericDescription.txt
.
- CPACK_PACKAGE_DESCRIPTION_SUMMARY¶
Short description of the project (only a few words). If the
CMAKE_PROJECT_DESCRIPTION
variable is set, it is used as the default value, otherwise the default will be a string generated by CMake based onCMAKE_PROJECT_NAME
.
- CPACK_PACKAGE_HOMEPAGE_URL¶
Project homepage URL. The default value is taken from the
CMAKE_PROJECT_HOMEPAGE_URL
variable, which is set by the top levelproject()
command, or else the default will be empty if no URL was provided toproject()
.
- CPACK_PACKAGE_FILE_NAME¶
The name of the package file to generate, not including the extension. For example,
cmake-2.6.1-Linux-i686
. The default value is:${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}
- CPACK_PACKAGE_INSTALL_DIRECTORY¶
Installation directory on the target system. This may be used by some CPack generators like NSIS to create an installation directory e.g., "CMake 2.5" below the installation prefix. All installed elements will be put inside this directory.
- CPACK_PACKAGE_ICON¶
A branding image that will be displayed inside the installer (used by GUI installers).
- CPACK_PACKAGE_CHECKSUM¶
New in version 3.7.
An algorithm that will be used to generate an additional file with the checksum of the package. The output file name will be:
${CPACK_PACKAGE_FILE_NAME}.${CPACK_PACKAGE_CHECKSUM}
Supported algorithms are those listed by the string(<HASH>) command.
- CPACK_PROJECT_CONFIG_FILE¶
CPack-time project CPack configuration file. This file is included at cpack time, once per generator after CPack has set
CPACK_GENERATOR
to the actual generator being used. It allows per-generator setting ofCPACK_*
variables at cpack time.
- CPACK_RESOURCE_FILE_LICENSE¶
License to be embedded in the installer. It will typically be displayed to the user by the produced installer (often with an explicit "Accept" button, for graphical installers) prior to installation. This license file is NOT added to the installed files but is used by some CPack generators like NSIS. If you want to install a license file (may be the same as this one) along with your project, you must add an appropriate CMake
install()
command in yourCMakeLists.txt
.
- CPACK_RESOURCE_FILE_README¶
ReadMe file to be embedded in the installer. It typically describes in some detail the purpose of the project during the installation. Not all CPack generators use this file.
- CPACK_RESOURCE_FILE_WELCOME¶
Welcome file to be embedded in the installer. It welcomes users to this installer. Typically used in the graphical installers on Windows and Mac OS X.
- CPACK_MONOLITHIC_INSTALL¶
Disables the component-based installation mechanism. When set, the component specification is ignored and all installed items are put in a single "MONOLITHIC" package. Some CPack generators do monolithic packaging by default and may be asked to do component packaging by setting
CPACK_<GENNAME>_COMPONENT_INSTALL
toTRUE
.
- CPACK_GENERATOR¶
List of CPack generators to use. If not specified, CPack will create a set of options following the naming pattern
CPACK_BINARY_<GENNAME>
(e.g.CPACK_BINARY_NSIS
) allowing the user to enable/disable individual generators. If the-G
option is given on thecpack
command line, it will override this variable and anyCPACK_BINARY_<GENNAME>
options.
- CPACK_OUTPUT_CONFIG_FILE¶
The name of the CPack binary configuration file. This file is the CPack configuration generated by the CPack module for binary installers. Defaults to
CPackConfig.cmake
.
- CPACK_PACKAGE_EXECUTABLES¶
Lists each of the executables and associated text label to be used to create Start Menu shortcuts. For example, setting this to the list
ccmake;CMake
will create a shortcut named "CMake" that will execute the installed executableccmake
. Not all CPack generators use it (at least NSIS, WIX and OSXX11 do).
- CPACK_STRIP_FILES¶
List of files to be stripped. Starting with CMake 2.6.0,
CPACK_STRIP_FILES
will be a boolean variable which enables stripping of all files (a list of files evaluates toTRUE
in CMake, so this change is compatible).
- CPACK_VERBATIM_VARIABLES¶
New in version 3.4.
If set to
TRUE
, values of variables prefixed withCPACK_
will be escaped before being written to the configuration files, so that the cpack program receives them exactly as they were specified. If not, characters like quotes and backslashes can cause parsing errors or alter the value received by the cpack program. Defaults toFALSE
for backwards compatibility.
- CPACK_THREADS¶
New in version 3.20.
Number of threads to use when performing parallelized operations, such as compressing the installer package.
Some compression methods used by CPack generators such as Debian or Archive may take advantage of multiple CPU cores to speed up compression.
CPACK_THREADS
can be set to specify how many threads will be used for compression.A positive integer can be used to specify an exact desired thread count.
When given a negative integer CPack will use the absolute value as the upper limit but may choose a lower value based on the available hardware concurrency.
Given 0 CPack will try to use all available CPU cores.
By default
CPACK_THREADS
is set to1
.Currently only
xz
compression may take advantage of multiple cores. Other compression methods ignore this value and use only one thread.New in version 3.21: Official CMake binaries available on
cmake.org
now ship with aliblzma
that supports parallel compression. Older versions did not.
Variables for Source Package Generators¶
The following CPack variables are specific to source packages, and will not affect binary packages:
- CPACK_SOURCE_PACKAGE_FILE_NAME¶
The name of the source package. For example
cmake-2.6.1
.
- CPACK_SOURCE_STRIP_FILES¶
List of files in the source tree that will be stripped. Starting with CMake 2.6.0,
CPACK_SOURCE_STRIP_FILES
will be a boolean variable which enables stripping of all files (a list of files evaluates toTRUE
in CMake, so this change is compatible).
- CPACK_SOURCE_GENERATOR¶
List of generators used for the source packages. As with
CPACK_GENERATOR
, if this is not specified then CPack will create a set of options (e.g.CPACK_SOURCE_ZIP
) allowing users to select which packages will be generated.
- CPACK_SOURCE_OUTPUT_CONFIG_FILE¶
The name of the CPack source configuration file. This file is the CPack configuration generated by the CPack module for source installers. Defaults to
CPackSourceConfig.cmake
.
- CPACK_SOURCE_IGNORE_FILES¶
Pattern of files in the source tree that won't be packaged when building a source package. This is a list of regular expression patterns (that must be properly escaped), e.g.,
/CVS/;/\\.svn/;\\.swp$;\\.#;/#;.*~;cscope.*
Variables for Advanced Use¶
The following variables are for advanced uses of CPack:
- CPACK_CMAKE_GENERATOR¶
What CMake generator should be used if the project is a CMake project. Defaults to the value of
CMAKE_GENERATOR
. Few users will want to change this setting.
- CPACK_INSTALL_CMAKE_PROJECTS¶
List of four values that specify what project to install. The four values are: Build directory, Project Name, Project Component, Directory. If omitted, CPack will build an installer that installs everything.
- CPACK_SYSTEM_NAME¶
System name, defaults to the value of
CMAKE_SYSTEM_NAME
, except on Windows where it will bewin32
orwin64
.
- CPACK_PACKAGE_VERSION¶
Package full version, used internally. By default, this is built from
CPACK_PACKAGE_VERSION_MAJOR
,CPACK_PACKAGE_VERSION_MINOR
, andCPACK_PACKAGE_VERSION_PATCH
.
- CPACK_TOPLEVEL_TAG¶
Directory for the installed files.
- CPACK_INSTALL_COMMANDS¶
Extra commands to install components. The environment variable
CMAKE_INSTALL_PREFIX
is set to the temporary install directory during execution.
- CPACK_INSTALL_SCRIPTS¶
New in version 3.16.
Extra CMake scripts executed by CPack during its local staging installation. They are executed before installing the files to be packaged. The scripts are not called by a standalone install (e.g.:
make install
). For every script, the following variables will be set:CMAKE_CURRENT_SOURCE_DIR
,CMAKE_CURRENT_BINARY_DIR
andCMAKE_INSTALL_PREFIX
(which is set to the staging install directory). The singular formCMAKE_INSTALL_SCRIPT
is supported as an alternative variable for historical reasons, but its value is ignored ifCMAKE_INSTALL_SCRIPTS
is set and a warning will be issued.See also
CPACK_PRE_BUILD_SCRIPTS
andCPACK_POST_BUILD_SCRIPTS
which can be used to specify scripts to be executed later in the packaging process.
- CPACK_PRE_BUILD_SCRIPTS¶
New in version 3.19.
List of CMake scripts to execute after CPack has installed the files to be packaged into a staging directory and before producing the package(s) from those files. See also
CPACK_INSTALL_SCRIPTS
andCPACK_POST_BUILD_SCRIPTS
.
- CPACK_POST_BUILD_SCRIPTS¶
New in version 3.19.
List of CMake scripts to execute after CPack has produced the resultant packages and before copying them back to the build directory. See also
CPACK_INSTALL_SCRIPTS
,CPACK_PRE_BUILD_SCRIPTS
andCPACK_PACKAGE_FILES
.
- CPACK_PACKAGE_FILES¶
New in version 3.19.
List of package files created in the staging directory, with each file provided as a full absolute path. This variable is populated by CPack just before invoking the post-build scripts listed in
CPACK_POST_BUILD_SCRIPTS
. It is the preferred way for the post-build scripts to know the set of package files to operate on. Projects should not try to set this variable themselves.
- CPACK_INSTALLED_DIRECTORIES¶
Extra directories to install.
- CPACK_PACKAGE_INSTALL_REGISTRY_KEY¶
Registry key used when installing this project. This is only used by installers for Windows. The default value is based on the installation directory.
- CPACK_CREATE_DESKTOP_LINKS¶
List of desktop links to create. Each desktop link requires a corresponding start menu shortcut as created by
CPACK_PACKAGE_EXECUTABLES
.
- CPACK_BINARY_<GENNAME>¶
CPack generated options for binary generators. The
CPack.cmake
module generates (whenCPACK_GENERATOR
is not set) a set of CMake options (see CMakeoption()
command) which may then be used to select the CPack generator(s) to be used when building thepackage
target or when runningcpack
without the-G
option.