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