1
0

CPack.cmake 33 KB

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