CPack provides many generators to create packages for a variety of platforms and packaging systems. The intention is for CMake/CPack to be a complete end-to-end solution for building and packaging a software project. However, it may not always be possible to use CPack for the entire packaging process, due to either technical limitations or policies that require the use of certain tools. For this reason, CPack provides the “External” generator, which allows external packaging software to take advantage of some of the functionality provided by CPack, such as component installation and the dependency graph.
The CPack External generator generates a .json file containing the CPack internal metadata, which gives external software information on how to package the software. External packaging software may itself invoke CPack, consume the generated metadata, install and package files as required.
Alternatively CPack can invoke an external packaging software through an optional custom CMake script in CPACK_EXTERNAL_PACKAGE_SCRIPT instead.
Staging of installation files may also optionally be taken care of by the generator when enabled through the CPACK_EXTERNAL_ENABLE_STAGING variable.
The JSON metadata file contains a list of CPack components and component groups, the various options passed to cpack_add_component() and cpack_add_component_group(), the dependencies between the components and component groups, and various other options passed to CPack.
The JSON’s root object will always provide two fields: formatVersionMajor and formatVersionMinor, which are always integers that describe the output format of the generator. Backwards-compatible changes to the output format (for example, adding a new field that didn’t exist before) cause the minor version to be incremented, and backwards-incompatible changes (for example, deleting a field or changing its meaning) cause the major version to be incremented and the minor version reset to 0. The format version is always of the format major.minor. In other words, it always has exactly two parts, separated by a period.
You can request one or more specific versions of the output format as described below with CPACK_EXTERNAL_REQUESTED_VERSIONS. The output format will have a major version that exactly matches the requested major version, and a minor version that is greater than or equal to the requested minor version. If no version is requested with CPACK_EXTERNAL_REQUESTED_VERSIONS, the latest known major version is used by default. Currently, the only supported format is 1.0, which is described below.
In addition to the standard format fields, format version 1.0 provides the following fields in the root:
The components field is an object with component names as the keys and objects describing the components as the values. The component objects have the following fields:
The componentGroups field is an object with component group names as the keys and objects describing the component groups as the values. The component group objects have the following fields:
The installationTypes field is an object with installation type names as the keys and objects describing the installation types as the values. The installation type objects have the following fields:
The projects field is an array of objects describing CMake projects which comprise the CPack project. The values in this field are derived from CPACK_INSTALL_CMAKE_PROJECTS. In most cases, this will be only a single project. The project objects have the following fields:
This variable is used to request a specific version of the CPack External generator. It is a list of major.minor values, separated by semicolons.
If this variable is set to a non-empty value, the CPack External generator will iterate through each item in the list to search for a version that it knows how to generate. Requested versions should be listed in order of descending preference by the client software, as the first matching version in the list will be generated.
The generator knows how to generate the version if it has a versioned generator whose major version exactly matches the requested major version, and whose minor version is greater than or equal to the requested minor version. For example, if CPACK_EXTERNAL_REQUESTED_VERSIONS contains 1.0, and the CPack External generator knows how to generate 1.1, it will generate 1.1. If the generator doesn’t know how to generate a version in the list, it skips the version and looks at the next one. If it doesn’t know how to generate any of the requested versions, an error is thrown.
If this variable is not set, or is empty, the CPack External generator will generate the highest major and minor version that it knows how to generate.
If an invalid version is encountered in CPACK_EXTERNAL_REQUESTED_VERSIONS (one that doesn’t match major.minor, where major and minor are integers), it is ignored.
This variable can be set to true to enable optional installation into a temporary staging area which can then be picked up and packaged by an external packaging tool. The top level directory used by CPack for the current packaging task is contained in CPACK_TOPLEVEL_DIRECTORY. It is automatically cleaned up on each run before packaging is initiated and can be used for custom temporary files required by the external packaging tool. It also contains the staging area CPACK_TEMPORARY_DIRECTORY into which CPack performs the installation when staging is enabled.
This variable can optionally specify the full path to a CMake script file to be run as part of the CPack invocation. It is invoked after (optional) staging took place and may run an external packaging tool. The script has access to the variables defined by the CPack config file.