1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
8 Configure generators for binary installers and source packages.
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.
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.
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
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.
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`.
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.
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``
60 * foreach generator, it then
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
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`.
71 For a list of available generators, see :manual:`cpack-generators(7)`.
73 .. _`packaging targets`:
75 Targets package and package_source
76 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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``.
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``.
91 Variables common to all CPack Generators
92 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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:
98 .. variable:: CPACK_PACKAGE_NAME
100 The name of the package (or application). If not specified, it defaults to
103 .. variable:: CPACK_PACKAGE_VENDOR
105 The name of the package vendor. (e.g., "Kitware"). The default is "Humanity".
107 .. variable:: CPACK_PACKAGE_DIRECTORY
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.
115 .. variable:: CPACK_PACKAGE_VERSION_MAJOR
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.
125 .. variable:: CPACK_PACKAGE_VERSION_MINOR
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
136 .. variable:: CPACK_PACKAGE_VERSION_PATCH
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
147 .. variable:: CPACK_PACKAGE_DESCRIPTION
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`.
154 .. variable:: CPACK_PACKAGE_DESCRIPTION_FILE
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``.
161 .. variable:: CPACK_PACKAGE_DESCRIPTION_SUMMARY
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`.
168 .. variable:: CPACK_PACKAGE_HOMEPAGE_URL
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`.
175 .. variable:: CPACK_PACKAGE_FILE_NAME
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
181 ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}
183 .. variable:: CPACK_PACKAGE_INSTALL_DIRECTORY
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.
190 .. variable:: CPACK_PACKAGE_ICON
192 A branding image that will be displayed inside the installer (used by GUI
195 .. variable:: CPACK_PACKAGE_CHECKSUM
197 .. versionadded:: 3.7
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::
202 ${CPACK_PACKAGE_FILE_NAME}.${CPACK_PACKAGE_CHECKSUM}
204 Supported algorithms are those listed by the
205 :ref:`string(\<HASH\>) <Supported Hash Algorithms>` command.
207 .. variable:: CPACK_PROJECT_CONFIG_FILE
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.
214 .. variable:: CPACK_RESOURCE_FILE_LICENSE
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``.
224 .. variable:: CPACK_RESOURCE_FILE_README
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.
230 .. variable:: CPACK_RESOURCE_FILE_WELCOME
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
236 .. variable:: CPACK_MONOLITHIC_INSTALL
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``.
244 .. variable:: CPACK_GENERATOR
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.
253 .. variable:: CPACK_OUTPUT_CONFIG_FILE
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``.
259 .. variable:: CPACK_PACKAGE_EXECUTABLES
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
267 .. variable:: CPACK_STRIP_FILES
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).
274 .. variable:: CPACK_VERBATIM_VARIABLES
276 .. versionadded:: 3.4
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
285 .. variable:: CPACK_THREADS
287 .. versionadded:: 3.20
289 Number of threads to use when performing parallelized operations, such
290 as compressing the installer package.
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.
297 A positive integer can be used to specify an exact desired thread count.
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.
303 Given 0 CPack will try to use all available CPU cores.
305 By default ``CPACK_THREADS`` is set to ``1``.
307 The following compression methods may take advantage of multiple cores:
310 Supported if CMake is built with a ``liblzma`` that supports
311 parallel compression.
313 .. versionadded:: 3.21
315 Official CMake binaries available on ``cmake.org`` now ship
316 with a ``liblzma`` that supports parallel compression.
317 Older versions did not.
320 .. versionadded:: 3.24
322 Supported if CMake is built with libarchive 3.6 or higher.
323 Official CMake binaries available on ``cmake.org`` support it.
325 Other compression methods ignore this value and use only one thread.
327 Variables for Source Package Generators
328 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
330 The following CPack variables are specific to source packages, and
331 will not affect binary packages:
333 .. variable:: CPACK_SOURCE_PACKAGE_FILE_NAME
335 The name of the source package. For example ``cmake-2.6.1``.
337 .. variable:: CPACK_SOURCE_STRIP_FILES
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).
344 .. variable:: CPACK_SOURCE_GENERATOR
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.
351 .. variable:: CPACK_SOURCE_OUTPUT_CONFIG_FILE
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``.
357 .. variable:: CPACK_SOURCE_IGNORE_FILES
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.*``
364 Variables for Advanced Use
365 ^^^^^^^^^^^^^^^^^^^^^^^^^^
367 The following variables are for advanced uses of CPack:
369 .. variable:: CPACK_CMAKE_GENERATOR
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.
375 .. variable:: CPACK_INSTALL_CMAKE_PROJECTS
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.
381 .. variable:: CPACK_SYSTEM_NAME
383 System name, defaults to the value of :variable:`CMAKE_SYSTEM_NAME`,
384 except on Windows where it will be ``win32`` or ``win64``.
386 .. variable:: CPACK_PACKAGE_VERSION
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`.
393 .. variable:: CPACK_TOPLEVEL_TAG
395 Directory for the installed files.
397 .. variable:: CPACK_INSTALL_COMMANDS
399 Extra commands to install components. The environment variable
400 ``CMAKE_INSTALL_PREFIX`` is set to the temporary install directory
403 .. variable:: CPACK_INSTALL_SCRIPTS
405 .. versionadded:: 3.16
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.
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.
421 .. variable:: CPACK_PRE_BUILD_SCRIPTS
423 .. versionadded:: 3.19
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`.
430 .. variable:: CPACK_POST_BUILD_SCRIPTS
432 .. versionadded:: 3.19
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`.
439 .. variable:: CPACK_PACKAGE_FILES
441 .. versionadded:: 3.19
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.
450 .. variable:: CPACK_INSTALLED_DIRECTORIES
452 Extra directories to install.
454 .. variable:: CPACK_PACKAGE_INSTALL_REGISTRY_KEY
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
460 .. variable:: CPACK_CREATE_DESKTOP_LINKS
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`.
466 .. variable:: CPACK_BINARY_<GENNAME>
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.
474 #]=======================================================================]
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!!")
480 set(CPack_CMake_INCLUDED 1)
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")
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")
493 # Backward compatibility
494 # Include CPackComponent macros if it has not already been included before.
495 include(CPackComponent)
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}")
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)
511 get_cmake_property(res VARIABLES)
513 if(var MATCHES "^CPACK")
514 if(CPACK_VERBATIM_VARIABLES)
515 _cpack_escape_for_cmake(value "${${var}}")
517 set(value "${${var}}")
520 string(APPEND commands "\nset(${var} \"${value}\")")
524 set(_CPACK_OTHER_VARIABLES_ "${commands}" PARENT_SCOPE)
527 # Internal use functions
528 function(_cpack_set_default name value)
529 if(NOT DEFINED "${name}")
530 set("${name}" "${value}" PARENT_SCOPE)
534 function(_cpack_escape_for_cmake var value)
535 string(REGEX REPLACE "([\\\$\"])" "\\\\\\1" escaped "${value}")
536 set("${var}" "${escaped}" PARENT_SCOPE)
539 # Set the package name
540 _cpack_set_default(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
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}")
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")
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}")
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}")
572 _cpack_set_default(CPACK_PACKAGE_DESCRIPTION_SUMMARY
573 "${CPACK_DEFAULT_PACKAGE_DESCRIPTION_SUMMARY}")
575 if(CMAKE_PROJECT_HOMEPAGE_URL)
576 _cpack_set_default(CPACK_PACKAGE_HOMEPAGE_URL
577 "${CMAKE_PROJECT_HOMEPAGE_URL}")
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")
591 _cpack_set_default(CPACK_MODULE_PATH "${CMAKE_MODULE_PATH}")
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}")
599 if(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL)
600 set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
603 if(CPACK_NSIS_MODIFY_PATH)
604 set(CPACK_NSIS_MODIFY_PATH ON)
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)
612 set(__cpack_system_name win32)
615 _cpack_set_default(CPACK_SYSTEM_NAME "${__cpack_system_name}")
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")
623 set(__cpack_root_default "$PROGRAMFILES")
625 _cpack_set_default(CPACK_NSIS_INSTALL_ROOT "${__cpack_root_default}")
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")
637 # always force to exactly "true" or "false" for CPack.Info.plist.in:
638 if(CPACK_PACKAGE_RELOCATABLE)
639 set(CPACK_PACKAGE_RELOCATABLE "true")
641 set(CPACK_PACKAGE_RELOCATABLE "false")
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.")
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")
655 macro(cpack_optional_append _list _cond _item)
657 set(${_list} ${${_list}} ${_item})
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
664 if(NOT CPACK_GENERATOR)
667 option(CPACK_BINARY_CYGWIN "Enable to build Cygwin binary packages" ON)
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)
675 CPACK_BINARY_DRAGNDROP
676 CPACK_BINARY_PRODUCTBUILD
679 option(CPACK_BINARY_TZ "Enable to build TZ packages" ON)
680 mark_as_advanced(CPACK_BINARY_TZ)
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)
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)
715 option(CPACK_BINARY_IFW "Enable to build IFW packages" OFF)
716 mark_as_advanced(CPACK_BINARY_IFW)
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)
739 # Provide options to choose source generators
740 if(NOT CPACK_SOURCE_GENERATOR)
743 option(CPACK_SOURCE_CYGWIN "Enable to build Cygwin source packages" ON)
744 mark_as_advanced(CPACK_SOURCE_CYGWIN)
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)
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)
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)
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)
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")
798 if(CPACK_NSIS_DISPLAY_NAME_SET)
799 _cpack_set_default(CPACK_NSIS_PACKAGE_NAME "${CPACK_NSIS_DISPLAY_NAME}")
801 _cpack_set_default(CPACK_NSIS_PACKAGE_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}")
804 _cpack_set_default(CPACK_OUTPUT_CONFIG_FILE
805 "${CMAKE_BINARY_DIR}/CPackConfig.cmake")
807 _cpack_set_default(CPACK_SOURCE_OUTPUT_CONFIG_FILE
808 "${CMAKE_BINARY_DIR}/CPackSourceConfig.cmake")
810 _cpack_set_default(CPACK_SET_DESTDIR OFF)
811 _cpack_set_default(CPACK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
813 _cpack_set_default(CPACK_NSIS_INSTALLER_ICON_CODE "")
814 _cpack_set_default(CPACK_NSIS_INSTALLER_MUI_ICON_CODE "")
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."
828 _cpack_set_default(CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE ON)
830 unset(_CPack_CMP0133)
833 # WiX specific variables
834 _cpack_set_default(CPACK_WIX_SIZEOF_VOID_P "${CMAKE_SIZEOF_VOID_P}")
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}")
841 _cpack_set_default(CPACK_BUILD_SOURCE_DIRS "${CMAKE_SOURCE_DIR};${CMAKE_BINARY_DIR}")
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)
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)
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)
865 set(CPACK_COMPONENTS_LEN)
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)
876 cpack_encode_variables()
877 configure_file("${cpack_input_file}" "${CPACK_OUTPUT_CONFIG_FILE}" @ONLY)
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")
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}")
892 _cpack_set_default(CPACK_SOURCE_IGNORE_FILES "${__cpack_source_ignore_files_default}")
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}")
902 set(CPACK_RPM_PACKAGE_SOURCES "ON")
904 cpack_encode_variables()
905 configure_file("${cpack_source_input_file}"
906 "${CPACK_SOURCE_OUTPUT_CONFIG_FILE}" @ONLY)