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