CPack.cmake 30 KB

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