CPack.cmake 32 KB

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