CPack.cmake 31 KB

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