CPack.cmake 32 KB

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