CPack.cmake 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. CPack
  5. -----
  6. Configure the binary and source package installers.
  7. Introduction
  8. ^^^^^^^^^^^^
  9. The CPack module generates the configuration files ``CPackConfig.cmake``
  10. and ``CPackSourceConfig.cmake``. They are intended for use in a subsequent
  11. run of the :manual:`cpack <cpack(1)>` program where they steer the generation
  12. of installers or/and source packages.
  13. Depending on the CMake generator, the CPack module may also add two new build
  14. targets, ``package`` and ``package_source``. See the targets_ section below
  15. for details.
  16. The generated binary installers contain everything installed via CMake's
  17. :command:`install` command (and the deprecated commands :command:`install_files`,
  18. :command:`install_programs`, and :command:`install_targets`).
  19. For certain kinds of binary installers (including the graphical
  20. installers on macOS and Windows), CPack generates installers that
  21. allow users to select individual application components to install.
  22. See :module:`CPackComponent` module for further details.
  23. CPack Generators
  24. ^^^^^^^^^^^^^^^^
  25. The :variable:`CPACK_GENERATOR` variable has different meanings in different
  26. contexts. In a ``CMakeLists.txt`` file, :variable:`CPACK_GENERATOR` is a
  27. *list of generators*: and when :manual:`cpack <cpack(1)>` is run with no other
  28. arguments, it will iterate over that list and produce one package for each
  29. generator. In a :variable:`CPACK_PROJECT_CONFIG_FILE`,
  30. :variable:`CPACK_GENERATOR` is a *string naming a single generator*. If you
  31. need per-cpack-generator logic to control *other* cpack settings, then you
  32. need a :variable:`CPACK_PROJECT_CONFIG_FILE`.
  33. The CMake source tree itself contains a :variable:`CPACK_PROJECT_CONFIG_FILE`.
  34. See the top level file ``CMakeCPackOptions.cmake.in`` for an example.
  35. If set, the :variable:`CPACK_PROJECT_CONFIG_FILE` is included automatically
  36. on a per-generator basis. It only need contain overrides.
  37. Here's how it works:
  38. * :manual:`cpack <cpack(1)>` runs
  39. * it includes ``CPackConfig.cmake``
  40. * it iterates over the generators given by the ``-G`` command line option,
  41. or if no such option was specified, over the list of generators given by
  42. the :variable:`CPACK_GENERATOR` variable set in the ``CPackConfig.cmake``
  43. input file.
  44. * foreach generator, it then
  45. - sets :variable:`CPACK_GENERATOR` to the one currently being iterated
  46. - includes the :variable:`CPACK_PROJECT_CONFIG_FILE`
  47. - produces the package for that generator
  48. This is the key: For each generator listed in :variable:`CPACK_GENERATOR` in
  49. ``CPackConfig.cmake``, cpack will *reset* :variable:`CPACK_GENERATOR`
  50. internally to *the one currently being used* and then include the
  51. :variable:`CPACK_PROJECT_CONFIG_FILE`.
  52. For a list of available generators, see :manual:`cpack-generators(7)`.
  53. .. _targets:
  54. Targets package and package_source
  55. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  56. If CMake is run with the Makefile, Ninja, or Xcode generator, then
  57. ``include(CPack)`` generates a target ``package``. This makes it possible
  58. to build a binary installer from CMake, Make, or Ninja: Instead of ``cpack``,
  59. one may call ``cmake --build . --target package`` or ``make package`` or
  60. ``ninja package``. The VS generator creates an uppercase target ``PACKAGE``.
  61. If CMake is run with the Makefile or Ninja generator, then ``include(CPack)``
  62. also generates a target ``package_source``. To build a source package,
  63. instead of ``cpack -G TGZ --config CPackConfig.cmake`` one may call
  64. ``cmake --build . --target package_source``, ``make package_source``,
  65. or ``ninja package_source``.
  66. Variables common to all CPack Generators
  67. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  68. Before including this CPack module in your ``CMakeLists.txt`` file, there
  69. are a variety of variables that can be set to customize the resulting
  70. installers. The most commonly-used variables are:
  71. .. variable:: CPACK_PACKAGE_NAME
  72. The name of the package (or application). If not specified, it defaults to
  73. the project name.
  74. .. variable:: CPACK_PACKAGE_VENDOR
  75. The name of the package vendor. (e.g., "Kitware"). The default is "Humanity".
  76. .. variable:: CPACK_PACKAGE_DIRECTORY
  77. The directory in which CPack is doing its packaging. If it is not set
  78. then this will default (internally) to the build dir. This variable may
  79. be defined in a CPack config file or from the :manual:`cpack <cpack(1)>`
  80. command line option ``-B``. If set, the command line option overrides the
  81. value found in the config file.
  82. .. variable:: CPACK_PACKAGE_VERSION_MAJOR
  83. Package major version. This variable will always be set, but its default
  84. value depends on whether or not version details were given to the
  85. :command:`project` command in the top level CMakeLists.txt file. If version
  86. details were given, the default value will be
  87. :variable:`CMAKE_PROJECT_VERSION_MAJOR`. If no version details were given,
  88. a default version of 0.1.1 will be assumed, leading to
  89. ``CPACK_PACKAGE_VERSION_MAJOR`` having a default value of 0.
  90. .. variable:: CPACK_PACKAGE_VERSION_MINOR
  91. Package minor version. The default value is determined based on whether or
  92. not version details were given to the :command:`project` command in the top
  93. level CMakeLists.txt file. If version details were given, the default
  94. value will be :variable:`CMAKE_PROJECT_VERSION_MINOR`, but if no minor
  95. version component was specified then ``CPACK_PACKAGE_VERSION_MINOR`` will be
  96. left unset. If no project version was given at all, a default version of
  97. 0.1.1 will be assumed, leading to ``CPACK_PACKAGE_VERSION_MINOR`` having a
  98. default value of 1.
  99. .. variable:: CPACK_PACKAGE_VERSION_PATCH
  100. Package patch version. The default value is determined based on whether or
  101. not version details were given to the :command:`project` command in the top
  102. level CMakeLists.txt file. If version details were given, the default
  103. value will be :variable:`CMAKE_PROJECT_VERSION_PATCH`, but if no patch
  104. version component was specified then ``CPACK_PACKAGE_VERSION_PATCH`` will be
  105. left unset. If no project version was given at all, a default version of
  106. 0.1.1 will be assumed, leading to ``CPACK_PACKAGE_VERSION_PATCH`` having a
  107. default value of 1.
  108. .. variable:: CPACK_PACKAGE_DESCRIPTION
  109. A description of the project, used in places such as the introduction
  110. screen of CPack-generated Windows installers. If not set, the value of
  111. this variable is populated from the file named by
  112. :variable:`CPACK_PACKAGE_DESCRIPTION_FILE`.
  113. .. variable:: CPACK_PACKAGE_DESCRIPTION_FILE
  114. A text file used to describe the project when
  115. :variable:`CPACK_PACKAGE_DESCRIPTION` is not explicitly set. The default
  116. value for ``CPACK_PACKAGE_DESCRIPTION_FILE`` points to a built-in template
  117. file ``Templates/CPack.GenericDescription.txt``.
  118. .. variable:: CPACK_PACKAGE_DESCRIPTION_SUMMARY
  119. Short description of the project (only a few words). If the
  120. :variable:`CMAKE_PROJECT_DESCRIPTION` variable is set, it is used as the
  121. default value, otherwise the default will be a string generated by CMake
  122. based on :variable:`CMAKE_PROJECT_NAME`.
  123. .. variable:: CPACK_PACKAGE_HOMEPAGE_URL
  124. Project homepage URL. The default value is taken from the
  125. :variable:`CMAKE_PROJECT_HOMEPAGE_URL` variable, which is set by the top
  126. level :command:`project` command, or else the default will be empty if no
  127. URL was provided to :command:`project`.
  128. .. variable:: CPACK_PACKAGE_FILE_NAME
  129. The name of the package file to generate, not including the
  130. extension. For example, ``cmake-2.6.1-Linux-i686``. The default value
  131. is::
  132. ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}
  133. .. variable:: CPACK_PACKAGE_INSTALL_DIRECTORY
  134. Installation directory on the target system. This may be used by some
  135. CPack generators like NSIS to create an installation directory e.g.,
  136. "CMake 2.5" below the installation prefix. All installed elements will be
  137. put inside this directory.
  138. .. variable:: CPACK_PACKAGE_ICON
  139. A branding image that will be displayed inside the installer (used by GUI
  140. installers).
  141. .. variable:: CPACK_PACKAGE_CHECKSUM
  142. An algorithm that will be used to generate an additional file with the
  143. checksum of the package. The output file name will be::
  144. ${CPACK_PACKAGE_FILE_NAME}.${CPACK_PACKAGE_CHECKSUM}
  145. Supported algorithms are those listed by the
  146. :ref:`string(\<HASH\>) <Supported Hash Algorithms>` command.
  147. .. variable:: CPACK_PROJECT_CONFIG_FILE
  148. CPack-time project CPack configuration file. This file is included at cpack
  149. time, once per generator after CPack has set :variable:`CPACK_GENERATOR`
  150. to the actual generator being used. It allows per-generator setting of
  151. ``CPACK_*`` variables at cpack time.
  152. .. variable:: CPACK_RESOURCE_FILE_LICENSE
  153. License to be embedded in the installer. It will typically be displayed
  154. to the user by the produced installer (often with an explicit "Accept"
  155. button, for graphical installers) prior to installation. This license
  156. file is NOT added to the installed files but is used by some CPack generators
  157. like NSIS. If you want to install a license file (may be the same as this
  158. one) along with your project, you must add an appropriate CMake
  159. :command:`install` command in your ``CMakeLists.txt``.
  160. .. variable:: CPACK_RESOURCE_FILE_README
  161. ReadMe file to be embedded in the installer. It typically describes in
  162. some detail the purpose of the project during the installation. Not all
  163. CPack generators use this file.
  164. .. variable:: CPACK_RESOURCE_FILE_WELCOME
  165. Welcome file to be embedded in the installer. It welcomes users to this
  166. installer. Typically used in the graphical installers on Windows and Mac
  167. OS X.
  168. .. variable:: CPACK_MONOLITHIC_INSTALL
  169. Disables the component-based installation mechanism. When set, the
  170. component specification is ignored and all installed items are put in a
  171. single "MONOLITHIC" package. Some CPack generators do monolithic
  172. packaging by default and may be asked to do component packaging by
  173. setting ``CPACK_<GENNAME>_COMPONENT_INSTALL`` to ``TRUE``.
  174. .. variable:: CPACK_GENERATOR
  175. List of CPack generators to use. If not specified, CPack will create a
  176. set of options following the naming pattern
  177. :variable:`CPACK_BINARY_<GENNAME>` (e.g. ``CPACK_BINARY_NSIS``) allowing
  178. the user to enable/disable individual generators. If the ``-G`` option is
  179. given on the :manual:`cpack <cpack(1)>` command line, it will override this
  180. variable and any ``CPACK_BINARY_<GENNAME>`` options.
  181. .. variable:: CPACK_OUTPUT_CONFIG_FILE
  182. The name of the CPack binary configuration file. This file is the CPack
  183. configuration generated by the CPack module for binary installers.
  184. Defaults to ``CPackConfig.cmake``.
  185. .. variable:: CPACK_PACKAGE_EXECUTABLES
  186. Lists each of the executables and associated text label to be used to
  187. create Start Menu shortcuts. For example, setting this to the list
  188. ``ccmake;CMake`` will create a shortcut named "CMake" that will execute the
  189. installed executable ``ccmake``. Not all CPack generators use it (at least
  190. NSIS, WIX and OSXX11 do).
  191. .. variable:: CPACK_STRIP_FILES
  192. List of files to be stripped. Starting with CMake 2.6.0,
  193. ``CPACK_STRIP_FILES`` will be a boolean variable which enables
  194. stripping of all files (a list of files evaluates to ``TRUE`` in CMake,
  195. so this change is compatible).
  196. .. variable:: CPACK_VERBATIM_VARIABLES
  197. If set to ``TRUE``, values of variables prefixed with ``CPACK_`` will be
  198. escaped before being written to the configuration files, so that the cpack
  199. program receives them exactly as they were specified. If not, characters
  200. like quotes and backslashes can cause parsing errors or alter the value
  201. received by the cpack program. Defaults to ``FALSE`` for backwards
  202. compatibility.
  203. Variables for Source Package Generators
  204. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  205. The following CPack variables are specific to source packages, and
  206. will not affect binary packages:
  207. .. variable:: CPACK_SOURCE_PACKAGE_FILE_NAME
  208. The name of the source package. For example ``cmake-2.6.1``.
  209. .. variable:: CPACK_SOURCE_STRIP_FILES
  210. List of files in the source tree that will be stripped. Starting with
  211. CMake 2.6.0, ``CPACK_SOURCE_STRIP_FILES`` will be a boolean
  212. variable which enables stripping of all files (a list of files evaluates
  213. to ``TRUE`` in CMake, so this change is compatible).
  214. .. variable:: CPACK_SOURCE_GENERATOR
  215. List of generators used for the source packages. As with
  216. :variable:`CPACK_GENERATOR`, if this is not specified then CPack will
  217. create a set of options (e.g. ``CPACK_SOURCE_ZIP``) allowing
  218. users to select which packages will be generated.
  219. .. variable:: CPACK_SOURCE_OUTPUT_CONFIG_FILE
  220. The name of the CPack source configuration file. This file is the CPack
  221. configuration generated by the CPack module for source installers.
  222. Defaults to ``CPackSourceConfig.cmake``.
  223. .. variable:: CPACK_SOURCE_IGNORE_FILES
  224. Pattern of files in the source tree that won't be packaged when building
  225. a source package. This is a list of regular expression patterns (that
  226. must be properly escaped), e.g.,
  227. ``/CVS/;/\\.svn/;\\.swp$;\\.#;/#;.*~;cscope.*``
  228. Variables for Advanced Use
  229. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  230. The following variables are for advanced uses of CPack:
  231. .. variable:: CPACK_CMAKE_GENERATOR
  232. What CMake generator should be used if the project is a CMake
  233. project. Defaults to the value of :variable:`CMAKE_GENERATOR`. Few users
  234. will want to change this setting.
  235. .. variable:: CPACK_INSTALL_CMAKE_PROJECTS
  236. List of four values that specify what project to install. The four values
  237. are: Build directory, Project Name, Project Component, Directory. If
  238. omitted, CPack will build an installer that installs everything.
  239. .. variable:: CPACK_SYSTEM_NAME
  240. System name, defaults to the value of :variable:`CMAKE_SYSTEM_NAME`,
  241. except on Windows where it will be ``win32`` or ``win64``.
  242. .. variable:: CPACK_PACKAGE_VERSION
  243. Package full version, used internally. By default, this is built from
  244. :variable:`CPACK_PACKAGE_VERSION_MAJOR`,
  245. :variable:`CPACK_PACKAGE_VERSION_MINOR`, and
  246. :variable:`CPACK_PACKAGE_VERSION_PATCH`.
  247. .. variable:: CPACK_TOPLEVEL_TAG
  248. Directory for the installed files.
  249. .. variable:: CPACK_INSTALL_COMMANDS
  250. Extra commands to install components. The environment variable
  251. ``CMAKE_INSTALL_PREFIX`` is set to the temporary install directory
  252. during execution.
  253. .. variable:: CPACK_INSTALL_SCRIPTS
  254. Extra CMake scripts executed by CPack during its local staging
  255. installation, which is done right before packaging the files.
  256. The scripts are not called by a standalone install (e.g.: ``make install``).
  257. For every script, the following variables will be set:
  258. :variable:`CMAKE_CURRENT_SOURCE_DIR`, :variable:`CMAKE_CURRENT_BINARY_DIR`
  259. and :variable:`CMAKE_INSTALL_PREFIX` (which is set to the staging install
  260. directory). The singular form ``CMAKE_INSTALL_SCRIPT`` is supported as
  261. an alternative variable for historical reasons, but its value is ignored if
  262. ``CMAKE_INSTALL_SCRIPTS`` is set and a warning will be issued.
  263. .. variable:: CPACK_INSTALLED_DIRECTORIES
  264. Extra directories to install.
  265. .. variable:: CPACK_PACKAGE_INSTALL_REGISTRY_KEY
  266. Registry key used when installing this project. This is only used by
  267. installers for Windows. The default value is based on the installation
  268. directory.
  269. .. variable:: CPACK_CREATE_DESKTOP_LINKS
  270. List of desktop links to create. Each desktop link requires a
  271. corresponding start menu shortcut as created by
  272. :variable:`CPACK_PACKAGE_EXECUTABLES`.
  273. .. variable:: CPACK_BINARY_<GENNAME>
  274. CPack generated options for binary generators. The ``CPack.cmake`` module
  275. generates (when :variable:`CPACK_GENERATOR` is not set) a set of CMake
  276. options (see CMake :command:`option` command) which may then be used to
  277. select the CPack generator(s) to be used when building the ``package``
  278. target or when running :manual:`cpack <cpack(1)>` without the ``-G`` option.
  279. #]=======================================================================]
  280. # Define this var in order to avoid (or warn) concerning multiple inclusion
  281. if(CPack_CMake_INCLUDED)
  282. message(WARNING "CPack.cmake has already been included!!")
  283. else()
  284. set(CPack_CMake_INCLUDED 1)
  285. endif()
  286. # Pick a configuration file
  287. set(cpack_input_file "${CMAKE_ROOT}/Templates/CPackConfig.cmake.in")
  288. if(EXISTS "${CMAKE_SOURCE_DIR}/CPackConfig.cmake.in")
  289. set(cpack_input_file "${CMAKE_SOURCE_DIR}/CPackConfig.cmake.in")
  290. endif()
  291. set(cpack_source_input_file "${CMAKE_ROOT}/Templates/CPackConfig.cmake.in")
  292. if(EXISTS "${CMAKE_SOURCE_DIR}/CPackSourceConfig.cmake.in")
  293. set(cpack_source_input_file "${CMAKE_SOURCE_DIR}/CPackSourceConfig.cmake.in")
  294. endif()
  295. # Backward compatibility
  296. # Include CPackComponent macros if it has not already been included before.
  297. include(CPackComponent)
  298. # Macro for setting values if a user did not overwrite them
  299. # Mangles CMake-special characters. Only kept for backwards compatibility.
  300. macro(cpack_set_if_not_set name value)
  301. message(DEPRECATION "cpack_set_if_not_set is obsolete; do not use.")
  302. _cpack_set_default("${name}" "${value}")
  303. endmacro()
  304. # cpack_encode_variables - Function to encode variables for the configuration file
  305. # find any variable that starts with CPACK and create a variable
  306. # _CPACK_OTHER_VARIABLES_ that contains SET commands for
  307. # each cpack variable. _CPACK_OTHER_VARIABLES_ is then
  308. # used as an @ replacment in configure_file for the CPackConfig.
  309. function(cpack_encode_variables)
  310. set(commands "")
  311. get_cmake_property(res VARIABLES)
  312. foreach(var ${res})
  313. if(var MATCHES "^CPACK")
  314. if(CPACK_VERBATIM_VARIABLES)
  315. _cpack_escape_for_cmake(value "${${var}}")
  316. else()
  317. set(value "${${var}}")
  318. endif()
  319. string(APPEND commands "\nset(${var} \"${value}\")")
  320. endif()
  321. endforeach()
  322. set(_CPACK_OTHER_VARIABLES_ "${commands}" PARENT_SCOPE)
  323. endfunction()
  324. # Internal use functions
  325. function(_cpack_set_default name value)
  326. if(NOT DEFINED "${name}")
  327. set("${name}" "${value}" PARENT_SCOPE)
  328. endif()
  329. endfunction()
  330. function(_cpack_escape_for_cmake var value)
  331. string(REGEX REPLACE "([\\\$\"])" "\\\\\\1" escaped "${value}")
  332. set("${var}" "${escaped}" PARENT_SCOPE)
  333. endfunction()
  334. # Set the package name
  335. _cpack_set_default(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
  336. # Set the package version
  337. if(CMAKE_PROJECT_VERSION_MAJOR GREATER_EQUAL 0)
  338. _cpack_set_default(CPACK_PACKAGE_VERSION_MAJOR "${CMAKE_PROJECT_VERSION_MAJOR}")
  339. if(CMAKE_PROJECT_VERSION_MINOR GREATER_EQUAL 0)
  340. _cpack_set_default(CPACK_PACKAGE_VERSION_MINOR "${CMAKE_PROJECT_VERSION_MINOR}")
  341. if(CMAKE_PROJECT_VERSION_PATCH GREATER_EQUAL 0)
  342. _cpack_set_default(CPACK_PACKAGE_VERSION_PATCH "${CMAKE_PROJECT_VERSION_PATCH}")
  343. endif()
  344. endif()
  345. else()
  346. _cpack_set_default(CPACK_PACKAGE_VERSION_MAJOR "0")
  347. _cpack_set_default(CPACK_PACKAGE_VERSION_MINOR "1")
  348. _cpack_set_default(CPACK_PACKAGE_VERSION_PATCH "1")
  349. endif()
  350. if(NOT DEFINED CPACK_PACKAGE_VERSION)
  351. set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}")
  352. if(CPACK_PACKAGE_VERSION_MINOR GREATER_EQUAL 0)
  353. string(APPEND CPACK_PACKAGE_VERSION ".${CPACK_PACKAGE_VERSION_MINOR}")
  354. if(CPACK_PACKAGE_VERSION_PATCH GREATER_EQUAL 0)
  355. string(APPEND CPACK_PACKAGE_VERSION ".${CPACK_PACKAGE_VERSION_PATCH}")
  356. endif()
  357. endif()
  358. endif()
  359. _cpack_set_default(CPACK_PACKAGE_VENDOR "Humanity")
  360. set(CPACK_DEFAULT_PACKAGE_DESCRIPTION_SUMMARY "${CMAKE_PROJECT_NAME} built using CMake")
  361. if(CMAKE_PROJECT_DESCRIPTION)
  362. _cpack_set_default(CPACK_PACKAGE_DESCRIPTION_SUMMARY
  363. "${CMAKE_PROJECT_DESCRIPTION}")
  364. else()
  365. _cpack_set_default(CPACK_PACKAGE_DESCRIPTION_SUMMARY
  366. "${CPACK_DEFAULT_PACKAGE_DESCRIPTION_SUMMARY}")
  367. endif()
  368. if(CMAKE_PROJECT_HOMEPAGE_URL)
  369. _cpack_set_default(CPACK_PACKAGE_HOMEPAGE_URL
  370. "${CMAKE_PROJECT_HOMEPAGE_URL}")
  371. endif()
  372. set(CPACK_DEFAULT_PACKAGE_DESCRIPTION_FILE
  373. "${CMAKE_ROOT}/Templates/CPack.GenericDescription.txt")
  374. _cpack_set_default(CPACK_PACKAGE_DESCRIPTION_FILE
  375. "${CPACK_DEFAULT_PACKAGE_DESCRIPTION_FILE}")
  376. _cpack_set_default(CPACK_RESOURCE_FILE_LICENSE
  377. "${CMAKE_ROOT}/Templates/CPack.GenericLicense.txt")
  378. _cpack_set_default(CPACK_RESOURCE_FILE_README
  379. "${CMAKE_ROOT}/Templates/CPack.GenericDescription.txt")
  380. _cpack_set_default(CPACK_RESOURCE_FILE_WELCOME
  381. "${CMAKE_ROOT}/Templates/CPack.GenericWelcome.txt")
  382. _cpack_set_default(CPACK_MODULE_PATH "${CMAKE_MODULE_PATH}")
  383. # Set default directory creation permissions mode
  384. if(CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS)
  385. _cpack_set_default(CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS
  386. "${CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS}")
  387. endif()
  388. if(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL)
  389. set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
  390. endif()
  391. if(CPACK_NSIS_MODIFY_PATH)
  392. set(CPACK_NSIS_MODIFY_PATH ON)
  393. endif()
  394. set(__cpack_system_name ${CMAKE_SYSTEM_NAME})
  395. if(__cpack_system_name MATCHES "Windows")
  396. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  397. set(__cpack_system_name win64)
  398. else()
  399. set(__cpack_system_name win32)
  400. endif()
  401. endif()
  402. _cpack_set_default(CPACK_SYSTEM_NAME "${__cpack_system_name}")
  403. # Root dir: default value should be the string literal "$PROGRAMFILES"
  404. # for backwards compatibility. Projects may set this value to anything.
  405. # When creating 64 bit binaries we set the default value to "$PROGRAMFILES64"
  406. if("x${__cpack_system_name}" STREQUAL "xwin64")
  407. set(__cpack_root_default "$PROGRAMFILES64")
  408. else()
  409. set(__cpack_root_default "$PROGRAMFILES")
  410. endif()
  411. _cpack_set_default(CPACK_NSIS_INSTALL_ROOT "${__cpack_root_default}")
  412. # <project>-<major>.<minor>.<patch>-<release>-<platform>.<pkgtype>
  413. _cpack_set_default(CPACK_PACKAGE_FILE_NAME
  414. "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}")
  415. _cpack_set_default(CPACK_PACKAGE_INSTALL_DIRECTORY
  416. "${CPACK_PACKAGE_NAME} ${CPACK_PACKAGE_VERSION}")
  417. _cpack_set_default(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
  418. "${CPACK_PACKAGE_INSTALL_DIRECTORY}")
  419. _cpack_set_default(CPACK_PACKAGE_DEFAULT_LOCATION "/")
  420. _cpack_set_default(CPACK_PACKAGE_RELOCATABLE "true")
  421. # always force to exactly "true" or "false" for CPack.Info.plist.in:
  422. if(CPACK_PACKAGE_RELOCATABLE)
  423. set(CPACK_PACKAGE_RELOCATABLE "true")
  424. else()
  425. set(CPACK_PACKAGE_RELOCATABLE "false")
  426. endif()
  427. macro(cpack_check_file_exists file description)
  428. if(NOT EXISTS "${file}")
  429. message(SEND_ERROR "CPack ${description} file: \"${file}\" could not be found.")
  430. endif()
  431. endmacro()
  432. cpack_check_file_exists("${CPACK_PACKAGE_DESCRIPTION_FILE}" "package description")
  433. cpack_check_file_exists("${CPACK_RESOURCE_FILE_LICENSE}" "license resource")
  434. cpack_check_file_exists("${CPACK_RESOURCE_FILE_README}" "readme resource")
  435. cpack_check_file_exists("${CPACK_RESOURCE_FILE_WELCOME}" "welcome resource")
  436. macro(cpack_optional_append _list _cond _item)
  437. if(${_cond})
  438. set(${_list} ${${_list}} ${_item})
  439. endif()
  440. endmacro()
  441. # Provide options to choose generators we might check here if the required
  442. # tools for the generators exist and set the defaults according to the
  443. # results.
  444. if(NOT CPACK_GENERATOR)
  445. if(UNIX)
  446. if(CYGWIN)
  447. option(CPACK_BINARY_CYGWIN "Enable to build Cygwin binary packages" ON)
  448. else()
  449. if(APPLE)
  450. option(CPACK_BINARY_BUNDLE "Enable to build OSX bundles" OFF)
  451. option(CPACK_BINARY_DRAGNDROP "Enable to build OSX Drag And Drop package" OFF)
  452. option(CPACK_BINARY_OSXX11 "Enable to build OSX X11 packages (deprecated)" OFF)
  453. option(CPACK_BINARY_PACKAGEMAKER "Enable to build PackageMaker packages (deprecated)" OFF)
  454. option(CPACK_BINARY_PRODUCTBUILD "Enable to build productbuild packages" OFF)
  455. mark_as_advanced(
  456. CPACK_BINARY_BUNDLE
  457. CPACK_BINARY_DRAGNDROP
  458. CPACK_BINARY_OSXX11
  459. CPACK_BINARY_PACKAGEMAKER
  460. CPACK_BINARY_PRODUCTBUILD
  461. )
  462. else()
  463. option(CPACK_BINARY_TZ "Enable to build TZ packages" ON)
  464. mark_as_advanced(CPACK_BINARY_TZ)
  465. endif()
  466. option(CPACK_BINARY_DEB "Enable to build Debian packages" OFF)
  467. option(CPACK_BINARY_FREEBSD "Enable to build FreeBSD packages" OFF)
  468. option(CPACK_BINARY_NSIS "Enable to build NSIS packages" OFF)
  469. option(CPACK_BINARY_RPM "Enable to build RPM packages" OFF)
  470. option(CPACK_BINARY_STGZ "Enable to build STGZ packages" ON)
  471. option(CPACK_BINARY_TBZ2 "Enable to build TBZ2 packages" OFF)
  472. option(CPACK_BINARY_TGZ "Enable to build TGZ packages" ON)
  473. option(CPACK_BINARY_TXZ "Enable to build TXZ packages" OFF)
  474. mark_as_advanced(
  475. CPACK_BINARY_DEB
  476. CPACK_BINARY_FREEBSD
  477. CPACK_BINARY_NSIS
  478. CPACK_BINARY_RPM
  479. CPACK_BINARY_STGZ
  480. CPACK_BINARY_TBZ2
  481. CPACK_BINARY_TGZ
  482. CPACK_BINARY_TXZ
  483. )
  484. endif()
  485. else()
  486. option(CPACK_BINARY_7Z "Enable to build 7-Zip packages" OFF)
  487. option(CPACK_BINARY_NSIS "Enable to build NSIS packages" ON)
  488. option(CPACK_BINARY_NUGET "Enable to build NuGet packages" OFF)
  489. option(CPACK_BINARY_WIX "Enable to build WiX packages" OFF)
  490. option(CPACK_BINARY_ZIP "Enable to build ZIP packages" OFF)
  491. mark_as_advanced(
  492. CPACK_BINARY_7Z
  493. CPACK_BINARY_NSIS
  494. CPACK_BINARY_NUGET
  495. CPACK_BINARY_WIX
  496. CPACK_BINARY_ZIP
  497. )
  498. endif()
  499. option(CPACK_BINARY_IFW "Enable to build IFW packages" OFF)
  500. mark_as_advanced(CPACK_BINARY_IFW)
  501. cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_7Z 7Z)
  502. cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_BUNDLE Bundle)
  503. cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_CYGWIN CygwinBinary)
  504. cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_DEB DEB)
  505. cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_DRAGNDROP DragNDrop)
  506. cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_FREEBSD FREEBSD)
  507. cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_IFW IFW)
  508. cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_NSIS NSIS)
  509. cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_NUGET NuGet)
  510. cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_OSXX11 OSXX11)
  511. cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_PACKAGEMAKER PackageMaker)
  512. cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_PRODUCTBUILD productbuild)
  513. cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_RPM RPM)
  514. cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_STGZ STGZ)
  515. cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_TBZ2 TBZ2)
  516. cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_TGZ TGZ)
  517. cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_TXZ TXZ)
  518. cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_TZ TZ)
  519. cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_WIX WIX)
  520. cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_ZIP ZIP)
  521. endif()
  522. # Provide options to choose source generators
  523. if(NOT CPACK_SOURCE_GENERATOR)
  524. if(UNIX)
  525. if(CYGWIN)
  526. option(CPACK_SOURCE_CYGWIN "Enable to build Cygwin source packages" ON)
  527. mark_as_advanced(CPACK_SOURCE_CYGWIN)
  528. else()
  529. option(CPACK_SOURCE_RPM "Enable to build RPM source packages" OFF)
  530. option(CPACK_SOURCE_TBZ2 "Enable to build TBZ2 source packages" ON)
  531. option(CPACK_SOURCE_TGZ "Enable to build TGZ source packages" ON)
  532. option(CPACK_SOURCE_TXZ "Enable to build TXZ source packages" ON)
  533. option(CPACK_SOURCE_TZ "Enable to build TZ source packages" ON)
  534. option(CPACK_SOURCE_ZIP "Enable to build ZIP source packages" OFF)
  535. mark_as_advanced(
  536. CPACK_SOURCE_RPM
  537. CPACK_SOURCE_TBZ2
  538. CPACK_SOURCE_TGZ
  539. CPACK_SOURCE_TXZ
  540. CPACK_SOURCE_TZ
  541. CPACK_SOURCE_ZIP
  542. )
  543. endif()
  544. else()
  545. option(CPACK_SOURCE_7Z "Enable to build 7-Zip source packages" ON)
  546. option(CPACK_SOURCE_ZIP "Enable to build ZIP source packages" ON)
  547. mark_as_advanced(
  548. CPACK_SOURCE_7Z
  549. CPACK_SOURCE_ZIP
  550. )
  551. endif()
  552. cpack_optional_append(CPACK_SOURCE_GENERATOR CPACK_SOURCE_7Z 7Z)
  553. cpack_optional_append(CPACK_SOURCE_GENERATOR CPACK_SOURCE_CYGWIN CygwinSource)
  554. cpack_optional_append(CPACK_SOURCE_GENERATOR CPACK_SOURCE_RPM RPM)
  555. cpack_optional_append(CPACK_SOURCE_GENERATOR CPACK_SOURCE_TBZ2 TBZ2)
  556. cpack_optional_append(CPACK_SOURCE_GENERATOR CPACK_SOURCE_TGZ TGZ)
  557. cpack_optional_append(CPACK_SOURCE_GENERATOR CPACK_SOURCE_TXZ TXZ)
  558. cpack_optional_append(CPACK_SOURCE_GENERATOR CPACK_SOURCE_TZ TZ)
  559. cpack_optional_append(CPACK_SOURCE_GENERATOR CPACK_SOURCE_ZIP ZIP)
  560. endif()
  561. # Set some other variables
  562. _cpack_set_default(CPACK_INSTALL_CMAKE_PROJECTS
  563. "${CMAKE_BINARY_DIR};${CMAKE_PROJECT_NAME};ALL;/")
  564. _cpack_set_default(CPACK_CMAKE_GENERATOR "${CMAKE_GENERATOR}")
  565. _cpack_set_default(CPACK_TOPLEVEL_TAG "${CPACK_SYSTEM_NAME}")
  566. # if the user has set CPACK_NSIS_DISPLAY_NAME remember it
  567. if(DEFINED CPACK_NSIS_DISPLAY_NAME)
  568. set(CPACK_NSIS_DISPLAY_NAME_SET TRUE)
  569. endif()
  570. # if the user has set CPACK_NSIS_DISPLAY
  571. # explicitly, then use that as the default
  572. # value of CPACK_NSIS_PACKAGE_NAME instead
  573. # of CPACK_PACKAGE_INSTALL_DIRECTORY
  574. _cpack_set_default(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}")
  575. # Specify the name of the Uninstall file in NSIS
  576. _cpack_set_default(CPACK_NSIS_UNINSTALL_NAME "Uninstall")
  577. if(CPACK_NSIS_DISPLAY_NAME_SET)
  578. _cpack_set_default(CPACK_NSIS_PACKAGE_NAME "${CPACK_NSIS_DISPLAY_NAME}")
  579. else()
  580. _cpack_set_default(CPACK_NSIS_PACKAGE_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}")
  581. endif()
  582. _cpack_set_default(CPACK_OUTPUT_CONFIG_FILE
  583. "${CMAKE_BINARY_DIR}/CPackConfig.cmake")
  584. _cpack_set_default(CPACK_SOURCE_OUTPUT_CONFIG_FILE
  585. "${CMAKE_BINARY_DIR}/CPackSourceConfig.cmake")
  586. _cpack_set_default(CPACK_SET_DESTDIR OFF)
  587. _cpack_set_default(CPACK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
  588. _cpack_set_default(CPACK_NSIS_INSTALLER_ICON_CODE "")
  589. _cpack_set_default(CPACK_NSIS_INSTALLER_MUI_ICON_CODE "")
  590. # WiX specific variables
  591. _cpack_set_default(CPACK_WIX_SIZEOF_VOID_P "${CMAKE_SIZEOF_VOID_P}")
  592. # set sysroot so SDK tools can be used
  593. if(CMAKE_OSX_SYSROOT)
  594. _cpack_set_default(CPACK_OSX_SYSROOT "${_CMAKE_OSX_SYSROOT_PATH}")
  595. endif()
  596. _cpack_set_default(CPACK_BUILD_SOURCE_DIRS "${CMAKE_SOURCE_DIR};${CMAKE_BINARY_DIR}")
  597. if(DEFINED CPACK_COMPONENTS_ALL)
  598. if(CPACK_MONOLITHIC_INSTALL)
  599. message("CPack warning: both CPACK_COMPONENTS_ALL and CPACK_MONOLITHIC_INSTALL have been set.\nDefaulting to a monolithic installation.")
  600. set(CPACK_COMPONENTS_ALL)
  601. else()
  602. # The user has provided the set of components to be installed as
  603. # part of a component-based installation; trust her.
  604. set(CPACK_COMPONENTS_ALL_SET_BY_USER TRUE)
  605. endif()
  606. else()
  607. # If the user has not specifically requested a monolithic installer
  608. # but has specified components in various "install" commands, tell
  609. # CPack about those components.
  610. if(NOT CPACK_MONOLITHIC_INSTALL)
  611. get_cmake_property(CPACK_COMPONENTS_ALL COMPONENTS)
  612. list(LENGTH CPACK_COMPONENTS_ALL CPACK_COMPONENTS_LEN)
  613. if(CPACK_COMPONENTS_LEN EQUAL 1)
  614. # Only one component: this is not a component-based installation
  615. # (at least, it isn't a component-based installation, but may
  616. # become one later if the user uses the cpack_add_* commands).
  617. set(CPACK_COMPONENTS_ALL)
  618. endif()
  619. set(CPACK_COMPONENTS_LEN)
  620. endif()
  621. endif()
  622. # CMake always generates a component named "Unspecified", which is
  623. # used to install everything that doesn't have an explicitly-provided
  624. # component. Since these files should always be installed, we'll make
  625. # them hidden and required.
  626. set(CPACK_COMPONENT_UNSPECIFIED_HIDDEN TRUE)
  627. set(CPACK_COMPONENT_UNSPECIFIED_REQUIRED TRUE)
  628. cpack_encode_variables()
  629. configure_file("${cpack_input_file}" "${CPACK_OUTPUT_CONFIG_FILE}" @ONLY)
  630. # Generate source file
  631. _cpack_set_default(CPACK_SOURCE_INSTALLED_DIRECTORIES
  632. "${CMAKE_SOURCE_DIR};/")
  633. _cpack_set_default(CPACK_SOURCE_TOPLEVEL_TAG "${CPACK_SYSTEM_NAME}-Source")
  634. _cpack_set_default(CPACK_SOURCE_PACKAGE_FILE_NAME
  635. "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Source")
  636. set(__cpack_source_ignore_files_default
  637. "/CVS/;/\\.svn/;/\\.bzr/;/\\.hg/;/\\.git/;\\.swp$;\\.#;/#")
  638. if(NOT CPACK_VERBATIM_VARIABLES)
  639. _cpack_escape_for_cmake(__cpack_source_ignore_files_default
  640. "${__cpack_source_ignore_files_default}")
  641. endif()
  642. _cpack_set_default(CPACK_SOURCE_IGNORE_FILES "${__cpack_source_ignore_files_default}")
  643. set(CPACK_INSTALL_CMAKE_PROJECTS "${CPACK_SOURCE_INSTALL_CMAKE_PROJECTS}")
  644. set(CPACK_INSTALLED_DIRECTORIES "${CPACK_SOURCE_INSTALLED_DIRECTORIES}")
  645. set(CPACK_GENERATOR "${CPACK_SOURCE_GENERATOR}")
  646. set(CPACK_TOPLEVEL_TAG "${CPACK_SOURCE_TOPLEVEL_TAG}")
  647. set(CPACK_PACKAGE_FILE_NAME "${CPACK_SOURCE_PACKAGE_FILE_NAME}")
  648. set(CPACK_IGNORE_FILES "${CPACK_SOURCE_IGNORE_FILES}")
  649. set(CPACK_STRIP_FILES "${CPACK_SOURCE_STRIP_FILES}")
  650. set(CPACK_RPM_PACKAGE_SOURCES "ON")
  651. cpack_encode_variables()
  652. configure_file("${cpack_source_input_file}"
  653. "${CPACK_SOURCE_OUTPUT_CONFIG_FILE}" @ONLY)