external.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. CPack External Generator
  2. ------------------------
  3. .. versionadded:: 3.13
  4. CPack provides many generators to create packages for a variety of platforms
  5. and packaging systems. The intention is for CMake/CPack to be a complete
  6. end-to-end solution for building and packaging a software project. However, it
  7. may not always be possible to use CPack for the entire packaging process, due
  8. to either technical limitations or policies that require the use of certain
  9. tools. For this reason, CPack provides the "External" generator, which allows
  10. external packaging software to take advantage of some of the functionality
  11. provided by CPack, such as component installation and the dependency graph.
  12. Integration with External Packaging Tools
  13. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  14. The CPack External generator generates a ``.json`` file containing the
  15. CPack internal metadata, which gives external software information
  16. on how to package the software. External packaging software may itself
  17. invoke CPack, consume the generated metadata,
  18. install and package files as required.
  19. Alternatively CPack can invoke an external packaging software
  20. through an optional custom CMake script in
  21. :variable:`CPACK_EXTERNAL_PACKAGE_SCRIPT` instead.
  22. Staging of installation files may also optionally be
  23. taken care of by the generator when enabled through the
  24. :variable:`CPACK_EXTERNAL_ENABLE_STAGING` variable.
  25. JSON Format
  26. ^^^^^^^^^^^
  27. The JSON metadata file contains a list of CPack components and component groups,
  28. the various options passed to :command:`cpack_add_component` and
  29. :command:`cpack_add_component_group`, the dependencies between the components
  30. and component groups, and various other options passed to CPack.
  31. The JSON's root object will always provide two fields:
  32. ``formatVersionMajor`` and ``formatVersionMinor``, which are always integers
  33. that describe the output format of the generator. Backwards-compatible changes
  34. to the output format (for example, adding a new field that didn't exist before)
  35. cause the minor version to be incremented, and backwards-incompatible changes
  36. (for example, deleting a field or changing its meaning) cause the major version
  37. to be incremented and the minor version reset to 0. The format version is
  38. always of the format ``major.minor``. In other words, it always has exactly two
  39. parts, separated by a period.
  40. You can request one or more specific versions of the output format as described
  41. below with :variable:`CPACK_EXTERNAL_REQUESTED_VERSIONS`. The output format will
  42. have a major version that exactly matches the requested major version, and a
  43. minor version that is greater than or equal to the requested minor version. If
  44. no version is requested with :variable:`CPACK_EXTERNAL_REQUESTED_VERSIONS`, the
  45. latest known major version is used by default. Currently, the only supported
  46. format is 1.0, which is described below.
  47. Version 1.0
  48. ***********
  49. In addition to the standard format fields, format version 1.0 provides the
  50. following fields in the root:
  51. ``components``
  52. The ``components`` field is an object with component names as the keys and
  53. objects describing the components as the values. The component objects have
  54. the following fields:
  55. ``name``
  56. The name of the component. This is always the same as the key in the
  57. ``components`` object.
  58. ``displayName``
  59. The value of the ``DISPLAY_NAME`` field passed to
  60. :command:`cpack_add_component`.
  61. ``description``
  62. The value of the ``DESCRIPTION`` field passed to
  63. :command:`cpack_add_component`.
  64. ``isHidden``
  65. True if ``HIDDEN`` was passed to :command:`cpack_add_component`, false if
  66. it was not.
  67. ``isRequired``
  68. True if ``REQUIRED`` was passed to :command:`cpack_add_component`, false if
  69. it was not.
  70. ``isDisabledByDefault``
  71. True if ``DISABLED`` was passed to :command:`cpack_add_component`, false if
  72. it was not.
  73. ``group``
  74. Only present if ``GROUP`` was passed to :command:`cpack_add_component`. If
  75. so, this field is a string value containing the component's group.
  76. ``dependencies``
  77. An array of components the component depends on. This contains the values
  78. in the ``DEPENDS`` argument passed to :command:`cpack_add_component`. If no
  79. ``DEPENDS`` argument was passed, this is an empty list.
  80. ``installationTypes``
  81. An array of installation types the component is part of. This contains the
  82. values in the ``INSTALL_TYPES`` argument passed to
  83. :command:`cpack_add_component`. If no ``INSTALL_TYPES`` argument was
  84. passed, this is an empty list.
  85. ``isDownloaded``
  86. True if ``DOWNLOADED`` was passed to :command:`cpack_add_component`, false
  87. if it was not.
  88. ``archiveFile``
  89. The name of the archive file passed with the ``ARCHIVE_FILE`` argument to
  90. :command:`cpack_add_component`. If no ``ARCHIVE_FILE`` argument was passed,
  91. this is an empty string.
  92. ``componentGroups``
  93. The ``componentGroups`` field is an object with component group names as the
  94. keys and objects describing the component groups as the values. The component
  95. group objects have the following fields:
  96. ``name``
  97. The name of the component group. This is always the same as the key in the
  98. ``componentGroups`` object.
  99. ``displayName``
  100. The value of the ``DISPLAY_NAME`` field passed to
  101. :command:`cpack_add_component_group`.
  102. ``description``
  103. The value of the ``DESCRIPTION`` field passed to
  104. :command:`cpack_add_component_group`.
  105. ``parentGroup``
  106. Only present if ``PARENT_GROUP`` was passed to
  107. :command:`cpack_add_component_group`. If so, this field is a string value
  108. containing the component group's parent group.
  109. ``isExpandedByDefault``
  110. True if ``EXPANDED`` was passed to :command:`cpack_add_component_group`,
  111. false if it was not.
  112. ``isBold``
  113. True if ``BOLD_TITLE`` was passed to :command:`cpack_add_component_group`,
  114. false if it was not.
  115. ``components``
  116. An array of names of components that are direct members of the group
  117. (components that have this group as their ``GROUP``). Components of
  118. subgroups are not included.
  119. ``subgroups``
  120. An array of names of component groups that are subgroups of the group
  121. (groups that have this group as their ``PARENT_GROUP``).
  122. ``installationTypes``
  123. The ``installationTypes`` field is an object with installation type names as
  124. the keys and objects describing the installation types as the values. The
  125. installation type objects have the following fields:
  126. ``name``
  127. The name of the installation type. This is always the same as the key in
  128. the ``installationTypes`` object.
  129. ``displayName``
  130. The value of the ``DISPLAY_NAME`` field passed to
  131. :command:`cpack_add_install_type`.
  132. ``index``
  133. The integer index of the installation type in the list.
  134. ``projects``
  135. The ``projects`` field is an array of objects describing CMake projects which
  136. comprise the CPack project. The values in this field are derived from
  137. :variable:`CPACK_INSTALL_CMAKE_PROJECTS`. In most cases, this will be only a
  138. single project. The project objects have the following fields:
  139. ``projectName``
  140. The project name passed to :variable:`CPACK_INSTALL_CMAKE_PROJECTS`.
  141. ``component``
  142. The name of the component or component set which comprises the project.
  143. ``directory``
  144. The build directory of the CMake project. This is the directory which
  145. contains the ``cmake_install.cmake`` script.
  146. ``subDirectory``
  147. The subdirectory to install the project into inside the CPack package.
  148. ``packageName``
  149. The package name given in :variable:`CPACK_PACKAGE_NAME`. Only present if
  150. this option is set.
  151. ``packageVersion``
  152. The package version given in :variable:`CPACK_PACKAGE_VERSION`. Only present
  153. if this option is set.
  154. ``packageDescriptionFile``
  155. The package description file given in
  156. :variable:`CPACK_PACKAGE_DESCRIPTION_FILE`. Only present if this option is
  157. set.
  158. ``packageDescriptionSummary``
  159. The package description summary given in
  160. :variable:`CPACK_PACKAGE_DESCRIPTION_SUMMARY`. Only present if this option is
  161. set.
  162. ``buildConfig``
  163. The build configuration given to CPack with the :option:`cpack -C` option.
  164. Only present if this option is set.
  165. ``defaultDirectoryPermissions``
  166. The default directory permissions given in
  167. :variable:`CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS`. Only present if this
  168. option is set.
  169. ``setDestdir``
  170. True if :variable:`CPACK_SET_DESTDIR` is true, false if it is not.
  171. ``packagingInstallPrefix``
  172. The install prefix given in :variable:`CPACK_PACKAGING_INSTALL_PREFIX`. Only
  173. present if :variable:`CPACK_SET_DESTDIR` is true.
  174. ``stripFiles``
  175. True if :variable:`CPACK_STRIP_FILES` is true, false if it is not.
  176. ``warnOnAbsoluteInstallDestination``
  177. True if :variable:`CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION` is true, false
  178. if it is not.
  179. ``errorOnAbsoluteInstallDestination``
  180. True if :variable:`CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION` is true,
  181. false if it is not.
  182. Variables specific to CPack External generator
  183. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  184. .. variable:: CPACK_EXTERNAL_REQUESTED_VERSIONS
  185. This variable is used to request a specific version of the CPack External
  186. generator. It is a list of ``major.minor`` values, separated by semicolons.
  187. If this variable is set to a non-empty value, the CPack External generator
  188. will iterate through each item in the list to search for a version that it
  189. knows how to generate. Requested versions should be listed in order of
  190. descending preference by the client software, as the first matching version
  191. in the list will be generated.
  192. The generator knows how to generate the version if it has a versioned
  193. generator whose major version exactly matches the requested major version,
  194. and whose minor version is greater than or equal to the requested minor
  195. version. For example, if ``CPACK_EXTERNAL_REQUESTED_VERSIONS`` contains 1.0, and
  196. the CPack External generator knows how to generate 1.1, it will generate 1.1.
  197. If the generator doesn't know how to generate a version in the list, it skips
  198. the version and looks at the next one. If it doesn't know how to generate any
  199. of the requested versions, an error is thrown.
  200. If this variable is not set, or is empty, the CPack External generator will
  201. generate the highest major and minor version that it knows how to generate.
  202. If an invalid version is encountered in ``CPACK_EXTERNAL_REQUESTED_VERSIONS`` (one
  203. that doesn't match ``major.minor``, where ``major`` and ``minor`` are
  204. integers), it is ignored.
  205. .. variable:: CPACK_EXTERNAL_ENABLE_STAGING
  206. This variable can be set to true to enable optional installation
  207. into a temporary staging area which can then be picked up
  208. and packaged by an external packaging tool.
  209. The top level directory used by CPack for the current packaging
  210. task is contained in ``CPACK_TOPLEVEL_DIRECTORY``.
  211. It is automatically cleaned up on each run before packaging is initiated
  212. and can be used for custom temporary files required by
  213. the external packaging tool.
  214. It also contains the staging area ``CPACK_TEMPORARY_DIRECTORY``
  215. into which CPack performs the installation when staging is enabled.
  216. .. variable:: CPACK_EXTERNAL_PACKAGE_SCRIPT
  217. This variable can optionally specify the full path to
  218. a CMake script file to be run as part of the CPack invocation.
  219. It is invoked after (optional) staging took place and may
  220. run an external packaging tool. The script has access to
  221. the variables defined by the CPack config file.
  222. .. variable:: CPACK_EXTERNAL_BUILT_PACKAGES
  223. .. versionadded:: 3.19
  224. The ``CPACK_EXTERNAL_PACKAGE_SCRIPT`` script may set this list variable to the
  225. full paths of generated package files. CPack will copy these files from the
  226. staging directory back to the top build directory and possibly produce
  227. checksum files if the :variable:`CPACK_PACKAGE_CHECKSUM` is set.