CPack.cmake 30.1 KB
Newer Older
1 2 3
# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

4 5 6 7 8 9
#[=======================================================================[.rst:
CPack
-----

Build binary and source package installers.

10 11
Introduction
^^^^^^^^^^^^
12

13 14 15 16 17 18 19 20 21 22
The CPack module generates a file ``CPackConfig.cmake`` intended for
use in a subsequent run of  the :manual:`cpack <cpack(1)>` program
where it steers the generation of installers or/and source packages.

Inclusion of the CPack module adds two new build targets, ``package``
and ``package_source``, which build the binary and source installers
respectively.  The generated binary installers contain everything
installed via CMake's :command:`install` command (and the deprecated
commands :command:`install_files`, :command:`install_programs`, and
:command:`install_targets`).
23 24

For certain kinds of binary installers (including the graphical
25
installers on macOS and Windows), CPack generates installers that
26
allow users to select individual application components to install.
27
See :module:`CPackComponent` module for further details.
28

29
CPack Generators
30 31
^^^^^^^^^^^^^^^^

32 33 34 35 36 37 38 39
The :variable:`CPACK_GENERATOR` variable has different meanings in different
contexts.  In a ``CMakeLists.txt`` file, :variable:`CPACK_GENERATOR` is a
*list of generators*: and when :manual:`cpack <cpack(1)>` is run with no other
arguments, it will iterate over that list and produce one package for each
generator.  In a :variable:`CPACK_PROJECT_CONFIG_FILE`,
:variable:`CPACK_GENERATOR` is a *string naming a single generator*.  If you
need per-cpack-generator logic to control *other* cpack settings, then you
need a :variable:`CPACK_PROJECT_CONFIG_FILE`.
40

41 42
The CMake source tree itself contains a :variable:`CPACK_PROJECT_CONFIG_FILE`.
See the top level file ``CMakeCPackOptions.cmake.in`` for an example.
43

44 45
If set, the :variable:`CPACK_PROJECT_CONFIG_FILE` is included automatically
on a per-generator basis.  It only need contain overrides.
46 47 48

Here's how it works:

49 50
* :manual:`cpack <cpack(1)>` runs
* it includes ``CPackConfig.cmake``
51 52
* it iterates over the generators given by the ``-G`` command line option,
  or if no such option was specified, over the list of generators given by
53 54
  the :variable:`CPACK_GENERATOR` variable set in the ``CPackConfig.cmake``
  input file.
55 56
* foreach generator, it then

57 58
  - sets :variable:`CPACK_GENERATOR` to the one currently being iterated
  - includes the :variable:`CPACK_PROJECT_CONFIG_FILE`
59 60
  - produces the package for that generator

61 62 63 64
This is the key: For each generator listed in :variable:`CPACK_GENERATOR` in
``CPackConfig.cmake``, cpack will *reset* :variable:`CPACK_GENERATOR`
internally to *the one currently being used* and then include the
:variable:`CPACK_PROJECT_CONFIG_FILE`.
65

66
Variables common to all CPack Generators
67 68
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

69
Before including this CPack module in your ``CMakeLists.txt`` file, there
70 71 72 73 74
are a variety of variables that can be set to customize the resulting
installers.  The most commonly-used variables are:

.. variable:: CPACK_PACKAGE_NAME

75 76
  The name of the package (or application).  If not specified, it defaults to
  the project name.
77 78 79

.. variable:: CPACK_PACKAGE_VENDOR

80
  The name of the package vendor. (e.g., "Kitware").  The default is "Humanity".
81 82 83

.. variable:: CPACK_PACKAGE_DIRECTORY

84 85 86 87 88
  The directory in which CPack is doing its packaging.  If it is not set
  then this will default (internally) to the build dir.  This variable may
  be defined in a CPack config file or from the :manual:`cpack <cpack(1)>`
  command line option ``-B``.  If set, the command line option overrides the
  value found in the config file.
89 90 91

.. variable:: CPACK_PACKAGE_VERSION_MAJOR

92 93 94 95 96 97 98
  Package major version.  This variable will always be set, but its default
  value depends on whether or not version details were given to the
  :command:`project` command in the top level CMakeLists.txt file.  If version
  details were given, the default value will be
  :variable:`CMAKE_PROJECT_VERSION_MAJOR`.  If no version details were given,
  a default version of 0.1.1 will be assumed, leading to
  ``CPACK_PACKAGE_VERSION_MAJOR`` having a default value of 0.
99 100 101

.. variable:: CPACK_PACKAGE_VERSION_MINOR

102 103 104 105 106 107 108 109
  Package minor version.  The default value is determined based on whether or
  not version details were given to the :command:`project` command in the top
  level CMakeLists.txt file.  If version details were given, the default
  value will be :variable:`CMAKE_PROJECT_VERSION_MINOR`, but if no minor
  version component was specified then ``CPACK_PACKAGE_VERSION_MINOR`` will be
  left unset.  If no project version was given at all, a default version of
  0.1.1 will be assumed, leading to ``CPACK_PACKAGE_VERSION_MINOR`` having a
  default value of 1.
110 111 112

.. variable:: CPACK_PACKAGE_VERSION_PATCH

113 114 115 116 117 118 119 120
  Package patch version.  The default value is determined based on whether or
  not version details were given to the :command:`project` command in the top
  level CMakeLists.txt file.  If version details were given, the default
  value will be :variable:`CMAKE_PROJECT_VERSION_PATCH`, but if no patch
  version component was specified then ``CPACK_PACKAGE_VERSION_PATCH`` will be
  left unset.  If no project version was given at all, a default version of
  0.1.1 will be assumed, leading to ``CPACK_PACKAGE_VERSION_PATCH`` having a
  default value of 1.
121

122 123 124 125 126
.. variable:: CPACK_PACKAGE_DESCRIPTION

  A description of the project, used in places such as the introduction
  screen of CPack-generated Windows installers.  If not set, the value of
  this variable is populated from the file named by
127
  :variable:`CPACK_PACKAGE_DESCRIPTION_FILE`.
128

129 130
.. variable:: CPACK_PACKAGE_DESCRIPTION_FILE

131
  A text file used to describe the project when
132
  :variable:`CPACK_PACKAGE_DESCRIPTION` is not explicitly set.  The default
133 134
  value for ``CPACK_PACKAGE_DESCRIPTION_FILE`` points to a built-in template
  file ``Templates/CPack.GenericDescription.txt``.
135 136 137

.. variable:: CPACK_PACKAGE_DESCRIPTION_SUMMARY

138 139 140 141
  Short description of the project (only a few words).  If the
  :variable:`CMAKE_PROJECT_DESCRIPTION` variable is set, it is used as the
  default value, otherwise the default will be a string generated by CMake
  based on :variable:`CMAKE_PROJECT_NAME`.
142 143 144

.. variable:: CPACK_PACKAGE_HOMEPAGE_URL

145 146 147 148
  Project homepage URL.  The default value is taken from the
  :variable:`CMAKE_PROJECT_HOMEPAGE_URL` variable, which is set by the top
  level :command:`project` command, or else the default will be empty if no
  URL was provided to :command:`project`.
149 150 151

.. variable:: CPACK_PACKAGE_FILE_NAME

152 153 154
  The name of the package file to generate, not including the
  extension.  For example, ``cmake-2.6.1-Linux-i686``.  The default value
  is::
155

156
    ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}
157 158 159

.. variable:: CPACK_PACKAGE_INSTALL_DIRECTORY

160 161 162 163
  Installation directory on the target system. This may be used by some
  CPack generators like NSIS to create an installation directory e.g.,
  "CMake 2.5" below the installation prefix.  All installed elements will be
  put inside this directory.
164 165 166

.. variable:: CPACK_PACKAGE_ICON

167 168
  A branding image that will be displayed inside the installer (used by GUI
  installers).
169 170 171

.. variable:: CPACK_PACKAGE_CHECKSUM

172 173
  An algorithm that will be used to generate an additional file with the
  checksum of the package.  The output file name will be::
174 175 176

    ${CPACK_PACKAGE_FILE_NAME}.${CPACK_PACKAGE_CHECKSUM}

177 178
  Supported algorithms are those listed by the
  :ref:`string(\<HASH\>) <Supported Hash Algorithms>` command.
179 180 181

.. variable:: CPACK_PROJECT_CONFIG_FILE

182 183 184 185
  CPack-time project CPack configuration file.  This file is included at cpack
  time, once per generator after CPack has set :variable:`CPACK_GENERATOR`
  to the actual generator being used.  It allows per-generator setting of
  ``CPACK_*`` variables at cpack time.
186 187 188

.. variable:: CPACK_RESOURCE_FILE_LICENSE

189 190 191 192 193 194 195
  License to be embedded in the installer.  It will typically be displayed
  to the user by the produced installer (often with an explicit "Accept"
  button, for graphical installers) prior to installation.  This license
  file is NOT added to the installed files but is used by some CPack generators
  like NSIS.  If you want to install a license file (may be the same as this
  one) along with your project, you must add an appropriate CMake
  :command:`install` command in your ``CMakeLists.txt``.
196 197 198

.. variable:: CPACK_RESOURCE_FILE_README

199 200 201
  ReadMe file to be embedded in the installer.  It typically describes in
  some detail the purpose of the project during the installation.  Not all
  CPack generators use this file.
202 203 204

.. variable:: CPACK_RESOURCE_FILE_WELCOME

205 206 207
  Welcome file to be embedded in the installer.  It welcomes users to this
  installer.  Typically used in the graphical installers on Windows and Mac
  OS X.
208 209 210

.. variable:: CPACK_MONOLITHIC_INSTALL

211 212 213 214 215
  Disables the component-based installation mechanism.  When set, the
  component specification is ignored and all installed items are put in a
  single "MONOLITHIC" package.  Some CPack generators do monolithic
  packaging by default and may be asked to do component packaging by
  setting ``CPACK_<GENNAME>_COMPONENT_INSTALL`` to ``TRUE``.
216 217 218

.. variable:: CPACK_GENERATOR

219 220 221 222 223 224
  List of CPack generators to use.  If not specified, CPack will create a
  set of options following the naming pattern
  :variable:`CPACK_BINARY_<GENNAME>` (e.g. ``CPACK_BINARY_NSIS``) allowing
  the user to enable/disable individual generators.  If the ``-G`` option is
  given on the :manual:`cpack <cpack(1)>` command line, it will override this
  variable and any ``CPACK_BINARY_<GENNAME>`` options.
225 226 227

.. variable:: CPACK_OUTPUT_CONFIG_FILE

228 229 230
  The name of the CPack binary configuration file.  This file is the CPack
  configuration generated by the CPack module for binary installers.
  Defaults to ``CPackConfig.cmake``.
231 232 233

.. variable:: CPACK_PACKAGE_EXECUTABLES

234 235 236 237 238
  Lists each of the executables and associated text label to be used to
  create Start Menu shortcuts.  For example, setting this to the list
  ``ccmake;CMake`` will create a shortcut named "CMake" that will execute the
  installed executable ``ccmake``.  Not all CPack generators use it (at least
  NSIS, WIX and OSXX11 do).
239 240 241

.. variable:: CPACK_STRIP_FILES

242 243 244 245
  List of files to be stripped.  Starting with CMake 2.6.0,
  ``CPACK_STRIP_FILES`` will be a boolean variable which enables
  stripping of all files (a list of files evaluates to ``TRUE`` in CMake,
  so this change is compatible).
246 247 248

.. variable:: CPACK_VERBATIM_VARIABLES

249 250 251 252 253 254
  If set to ``TRUE``, values of variables prefixed with ``CPACK_`` will be
  escaped before being written to the configuration files, so that the cpack
  program receives them exactly as they were specified.  If not, characters
  like quotes and backslashes can cause parsing errors or alter the value
  received by the cpack program.  Defaults to ``FALSE`` for backwards
  compatibility.
255

256 257 258
Variables for Source Package Generators
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

259 260 261 262 263
The following CPack variables are specific to source packages, and
will not affect binary packages:

.. variable:: CPACK_SOURCE_PACKAGE_FILE_NAME

264
  The name of the source package.  For example ``cmake-2.6.1``.
265 266 267

.. variable:: CPACK_SOURCE_STRIP_FILES

268 269 270 271
  List of files in the source tree that will be stripped.  Starting with
  CMake 2.6.0, ``CPACK_SOURCE_STRIP_FILES`` will be a boolean
  variable which enables stripping of all files (a list of files evaluates
  to ``TRUE`` in CMake, so this change is compatible).
272 273 274

.. variable:: CPACK_SOURCE_GENERATOR

275 276 277 278
  List of generators used for the source packages.  As with
  :variable:`CPACK_GENERATOR`, if this is not specified then CPack will
  create a set of options (e.g. ``CPACK_SOURCE_ZIP``) allowing
  users to select which packages will be generated.
279 280 281

.. variable:: CPACK_SOURCE_OUTPUT_CONFIG_FILE

282 283 284
  The name of the CPack source configuration file.  This file is the CPack
  configuration generated by the CPack module for source installers.
  Defaults to ``CPackSourceConfig.cmake``.
285 286 287

.. variable:: CPACK_SOURCE_IGNORE_FILES

288 289 290 291
  Pattern of files in the source tree that won't be packaged when building
  a source package.  This is a list of regular expression patterns (that
  must be properly escaped), e.g.,
  ``/CVS/;/\\.svn/;\\.swp$;\\.#;/#;.*~;cscope.*``
292

293 294 295
Variables for Advanced Use
^^^^^^^^^^^^^^^^^^^^^^^^^^

296 297 298 299
The following variables are for advanced uses of CPack:

.. variable:: CPACK_CMAKE_GENERATOR

300 301 302
  What CMake generator should be used if the project is a CMake
  project.  Defaults to the value of :variable:`CMAKE_GENERATOR`.  Few users
  will want to change this setting.
303 304 305

.. variable:: CPACK_INSTALL_CMAKE_PROJECTS

306 307 308
  List of four values that specify what project to install.  The four values
  are: Build directory, Project Name, Project Component, Directory.  If
  omitted, CPack will build an installer that installs everything.
309 310 311

.. variable:: CPACK_SYSTEM_NAME

312 313
  System name, defaults to the value of :variable:`CMAKE_SYSTEM_NAME`,
  except on Windows where it will be ``win32`` or ``win64``.
314 315 316

.. variable:: CPACK_PACKAGE_VERSION

317 318 319 320
  Package full version, used internally.  By default, this is built from
  :variable:`CPACK_PACKAGE_VERSION_MAJOR`,
  :variable:`CPACK_PACKAGE_VERSION_MINOR`, and
  :variable:`CPACK_PACKAGE_VERSION_PATCH`.
321 322 323

.. variable:: CPACK_TOPLEVEL_TAG

324
  Directory for the installed files.
325 326 327

.. variable:: CPACK_INSTALL_COMMANDS

328
  Extra commands to install components.
329 330 331

.. variable:: CPACK_INSTALLED_DIRECTORIES

332
  Extra directories to install.
333 334 335

.. variable:: CPACK_PACKAGE_INSTALL_REGISTRY_KEY

336 337 338
  Registry key used when installing this project.  This is only used by
  installers for Windows.  The default value is based on the installation
  directory.
339 340 341

.. variable:: CPACK_CREATE_DESKTOP_LINKS

342 343 344
  List of desktop links to create.  Each desktop link requires a
  corresponding start menu shortcut as created by
  :variable:`CPACK_PACKAGE_EXECUTABLES`.
345 346 347

.. variable:: CPACK_BINARY_<GENNAME>

348 349 350 351 352 353
  CPack generated options for binary generators.  The ``CPack.cmake`` module
  generates (when :variable:`CPACK_GENERATOR` is not set) a set of CMake
  options (see CMake :command:`option` command) which may then be used to
  select the CPack generator(s) to be used when building the ``package``
  target or when running :manual:`cpack <cpack(1)>` without the ``-G`` option.

354
#]=======================================================================]
355

356
# Define this var in order to avoid (or warn) concerning multiple inclusion
357 358
if(CPack_CMake_INCLUDED)
  message(WARNING "CPack.cmake has already been included!!")
359
else()
360
  set(CPack_CMake_INCLUDED 1)
361
endif()
362

363
# Pick a configuration file
364 365 366
set(cpack_input_file "${CMAKE_ROOT}/Templates/CPackConfig.cmake.in")
if(EXISTS "${CMAKE_SOURCE_DIR}/CPackConfig.cmake.in")
  set(cpack_input_file "${CMAKE_SOURCE_DIR}/CPackConfig.cmake.in")
367
endif()
368 369 370
set(cpack_source_input_file "${CMAKE_ROOT}/Templates/CPackConfig.cmake.in")
if(EXISTS "${CMAKE_SOURCE_DIR}/CPackSourceConfig.cmake.in")
  set(cpack_source_input_file "${CMAKE_SOURCE_DIR}/CPackSourceConfig.cmake.in")
371
endif()
372

373 374 375
# Backward compatibility
# Include CPackComponent macros if it has not already been included before.
include(CPackComponent)
376

377
# Macro for setting values if a user did not overwrite them
378
# Mangles CMake-special characters. Only kept for backwards compatibility.
379
macro(cpack_set_if_not_set name value)
380 381
  message(DEPRECATION "cpack_set_if_not_set is obsolete; do not use.")
  _cpack_set_default("${name}" "${value}")
382
endmacro()
383

384
# cpack_encode_variables - Function to encode variables for the configuration file
385
# find any variable that starts with CPACK and create a variable
Bill Hoffman's avatar
Bill Hoffman committed
386 387 388
# _CPACK_OTHER_VARIABLES_ that contains SET commands for
# each cpack variable.  _CPACK_OTHER_VARIABLES_ is then
# used as an @ replacment in configure_file for the CPackConfig.
389 390
function(cpack_encode_variables)
  set(commands "")
391 392
  get_cmake_property(res VARIABLES)
  foreach(var ${res})
393
    if(var MATCHES "^CPACK")
394 395 396 397
      if(CPACK_VERBATIM_VARIABLES)
        _cpack_escape_for_cmake(value "${${var}}")
      else()
        set(value "${${var}}")
398
      endif()
399

400
      string(APPEND commands "\nset(${var} \"${value}\")")
401
    endif()
402
  endforeach()
403 404 405

  set(_CPACK_OTHER_VARIABLES_ "${commands}" PARENT_SCOPE)
endfunction()
406

407 408 409 410 411 412 413
# Internal use functions
function(_cpack_set_default name value)
  if(NOT DEFINED "${name}")
    set("${name}" "${value}" PARENT_SCOPE)
  endif()
endfunction()

414 415 416 417 418
function(_cpack_escape_for_cmake var value)
  string(REGEX REPLACE "([\\\$\"])" "\\\\\\1" escaped "${value}")
  set("${var}" "${escaped}" PARENT_SCOPE)
endfunction()

419
# Set the package name
420
_cpack_set_default(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
421 422 423

# Set the package version
if(CMAKE_PROJECT_VERSION_MAJOR GREATER_EQUAL 0)
Craig Scott's avatar
Craig Scott committed
424
  _cpack_set_default(CPACK_PACKAGE_VERSION_MAJOR "${CMAKE_PROJECT_VERSION_MAJOR}")
425
  if(CMAKE_PROJECT_VERSION_MINOR GREATER_EQUAL 0)
Craig Scott's avatar
Craig Scott committed
426
    _cpack_set_default(CPACK_PACKAGE_VERSION_MINOR "${CMAKE_PROJECT_VERSION_MINOR}")
427
    if(CMAKE_PROJECT_VERSION_PATCH GREATER_EQUAL 0)
Craig Scott's avatar
Craig Scott committed
428
      _cpack_set_default(CPACK_PACKAGE_VERSION_PATCH "${CMAKE_PROJECT_VERSION_PATCH}")
429
    endif()
Craig Scott's avatar
Craig Scott committed
430
  endif()
431
else()
Craig Scott's avatar
Craig Scott committed
432 433 434
  _cpack_set_default(CPACK_PACKAGE_VERSION_MAJOR "0")
  _cpack_set_default(CPACK_PACKAGE_VERSION_MINOR "1")
  _cpack_set_default(CPACK_PACKAGE_VERSION_PATCH "1")
435
endif()
436 437 438 439 440 441 442 443 444 445
if(NOT DEFINED CPACK_PACKAGE_VERSION)
  set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}")
  if(CPACK_PACKAGE_VERSION_MINOR GREATER_EQUAL 0)
    string(APPEND CPACK_PACKAGE_VERSION ".${CPACK_PACKAGE_VERSION_MINOR}")
    if(CPACK_PACKAGE_VERSION_PATCH GREATER_EQUAL 0)
      string(APPEND CPACK_PACKAGE_VERSION ".${CPACK_PACKAGE_VERSION_PATCH}")
    endif()
  endif()
endif()

446
_cpack_set_default(CPACK_PACKAGE_VENDOR "Humanity")
447 448 449 450 451 452 453
if(CMAKE_PROJECT_DESCRIPTION)
  _cpack_set_default(CPACK_PACKAGE_DESCRIPTION_SUMMARY
    "${CMAKE_PROJECT_DESCRIPTION}")
else()
  _cpack_set_default(CPACK_PACKAGE_DESCRIPTION_SUMMARY
    "${CMAKE_PROJECT_NAME} built using CMake")
endif()
454 455 456 457
if(CMAKE_PROJECT_HOMEPAGE_URL)
  _cpack_set_default(CPACK_PACKAGE_HOMEPAGE_URL
    "${CMAKE_PROJECT_HOMEPAGE_URL}")
endif()
458

459
_cpack_set_default(CPACK_PACKAGE_DESCRIPTION_FILE
Andy Cedilnik's avatar
Andy Cedilnik committed
460
  "${CMAKE_ROOT}/Templates/CPack.GenericDescription.txt")
461
_cpack_set_default(CPACK_RESOURCE_FILE_LICENSE
462
  "${CMAKE_ROOT}/Templates/CPack.GenericLicense.txt")
463
_cpack_set_default(CPACK_RESOURCE_FILE_README
464
  "${CMAKE_ROOT}/Templates/CPack.GenericDescription.txt")
465
_cpack_set_default(CPACK_RESOURCE_FILE_WELCOME
466
  "${CMAKE_ROOT}/Templates/CPack.GenericWelcome.txt")
467

468
_cpack_set_default(CPACK_MODULE_PATH "${CMAKE_MODULE_PATH}")
469

470 471 472 473 474 475
# Set default directory creation permissions mode
if(CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS)
  _cpack_set_default(CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS
    "${CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS}")
endif()

476 477
if(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL)
  set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
478
endif()
479 480 481

if(CPACK_NSIS_MODIFY_PATH)
  set(CPACK_NSIS_MODIFY_PATH ON)
482
endif()
483 484

set(__cpack_system_name ${CMAKE_SYSTEM_NAME})
485 486
if(__cpack_system_name MATCHES "Windows")
  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
487
    set(__cpack_system_name win64)
488
  else()
489
    set(__cpack_system_name win32)
490 491
  endif()
endif()
492
_cpack_set_default(CPACK_SYSTEM_NAME "${__cpack_system_name}")
493

494 495
# Root dir: default value should be the string literal "$PROGRAMFILES"
# for backwards compatibility. Projects may set this value to anything.
496 497 498 499 500 501
# When creating 64 bit binaries we set the default value to "$PROGRAMFILES64"
if("x${__cpack_system_name}" STREQUAL "xwin64")
  set(__cpack_root_default "$PROGRAMFILES64")
else()
  set(__cpack_root_default "$PROGRAMFILES")
endif()
502
_cpack_set_default(CPACK_NSIS_INSTALL_ROOT "${__cpack_root_default}")
503

504
# <project>-<major>.<minor>.<patch>-<release>-<platform>.<pkgtype>
505
_cpack_set_default(CPACK_PACKAGE_FILE_NAME
506
  "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}")
507
_cpack_set_default(CPACK_PACKAGE_INSTALL_DIRECTORY
508
  "${CPACK_PACKAGE_NAME} ${CPACK_PACKAGE_VERSION}")
509
_cpack_set_default(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
510
  "${CPACK_PACKAGE_INSTALL_DIRECTORY}")
511 512
_cpack_set_default(CPACK_PACKAGE_DEFAULT_LOCATION "/")
_cpack_set_default(CPACK_PACKAGE_RELOCATABLE "true")
513 514 515 516

# always force to exactly "true" or "false" for CPack.Info.plist.in:
if(CPACK_PACKAGE_RELOCATABLE)
  set(CPACK_PACKAGE_RELOCATABLE "true")
517
else()
518
  set(CPACK_PACKAGE_RELOCATABLE "false")
519
endif()
520

521 522 523
macro(cpack_check_file_exists file description)
  if(NOT EXISTS "${file}")
    message(SEND_ERROR "CPack ${description} file: \"${file}\" could not be found.")
524 525
  endif()
endmacro()
526

527 528 529 530
cpack_check_file_exists("${CPACK_PACKAGE_DESCRIPTION_FILE}" "package description")
cpack_check_file_exists("${CPACK_RESOURCE_FILE_LICENSE}"    "license resource")
cpack_check_file_exists("${CPACK_RESOURCE_FILE_README}"     "readme resource")
cpack_check_file_exists("${CPACK_RESOURCE_FILE_WELCOME}"    "welcome resource")
531

532 533 534
macro(cpack_optional_append _list _cond _item)
  if(${_cond})
    set(${_list} ${${_list}} ${_item})
535 536
  endif()
endmacro()
537

538 539 540
# Provide options to choose generators we might check here if the required
# tools for the generators exist and set the defaults according to the
# results.
541 542 543
if(NOT CPACK_GENERATOR)
  if(UNIX)
    if(CYGWIN)
544
      option(CPACK_BINARY_CYGWIN "Enable to build Cygwin binary packages" ON)
545
    else()
546
      if(APPLE)
547
        option(CPACK_BINARY_BUNDLE       "Enable to build OSX bundles"      OFF)
548
        option(CPACK_BINARY_DRAGNDROP    "Enable to build OSX Drag And Drop package" OFF)
549
        option(CPACK_BINARY_OSXX11       "Enable to build OSX X11 packages"      OFF)
550
        option(CPACK_BINARY_PACKAGEMAKER "Enable to build PackageMaker packages" OFF)
551
        option(CPACK_BINARY_PRODUCTBUILD "Enable to build productbuild packages" OFF)
552
      else()
553
        option(CPACK_BINARY_TZ  "Enable to build TZ packages"     ON)
554
      endif()
555
      option(CPACK_BINARY_DEB  "Enable to build Debian packages"  OFF)
556
      option(CPACK_BINARY_FREEBSD  "Enable to build FreeBSD packages"  OFF)
557 558
      option(CPACK_BINARY_NSIS "Enable to build NSIS packages"    OFF)
      option(CPACK_BINARY_RPM  "Enable to build RPM packages"     OFF)
559
      option(CPACK_BINARY_STGZ "Enable to build STGZ packages"    ON)
560
      option(CPACK_BINARY_TBZ2 "Enable to build TBZ2 packages"    OFF)
561
      option(CPACK_BINARY_TGZ  "Enable to build TGZ packages"     ON)
562
      option(CPACK_BINARY_TXZ  "Enable to build TXZ packages"     OFF)
563 564
    endif()
  else()
Alex Turbov's avatar
Alex Turbov committed
565 566 567 568 569
    option(CPACK_BINARY_7Z    "Enable to build 7-Zip packages" OFF)
    option(CPACK_BINARY_NSIS  "Enable to build NSIS packages" ON)
    option(CPACK_BINARY_NUGET "Enable to build NuGet packages" OFF)
    option(CPACK_BINARY_WIX   "Enable to build WiX packages" OFF)
    option(CPACK_BINARY_ZIP   "Enable to build ZIP packages" OFF)
570
  endif()
571
  option(CPACK_BINARY_IFW "Enable to build IFW packages" OFF)
572

573
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_7Z           7Z)
574
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_BUNDLE       Bundle)
575 576
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_CYGWIN       CygwinBinary)
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_DEB          DEB)
577
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_DRAGNDROP    DragNDrop)
578
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_FREEBSD      FREEBSD)
579
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_IFW          IFW)
580
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_NSIS         NSIS)
Alex Turbov's avatar
Alex Turbov committed
581
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_NUGET        NuGet)
582 583
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_OSXX11       OSXX11)
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_PACKAGEMAKER PackageMaker)
584
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_PRODUCTBUILD productbuild)
585
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_RPM          RPM)
586 587
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_STGZ         STGZ)
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_TBZ2         TBZ2)
588
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_TGZ          TGZ)
589
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_TXZ          TXZ)
590
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_TZ           TZ)
591
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_WIX          WIX)
592
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_ZIP          ZIP)
593

594
endif()
595 596 597 598 599 600

# Provide options to choose source generators
if(NOT CPACK_SOURCE_GENERATOR)
  if(UNIX)
    if(CYGWIN)
      option(CPACK_SOURCE_CYGWIN "Enable to build Cygwin source packages" ON)
601
    else()
602
      option(CPACK_SOURCE_RPM  "Enable to build RPM source packages"  OFF)
603 604
      option(CPACK_SOURCE_TBZ2 "Enable to build TBZ2 source packages" ON)
      option(CPACK_SOURCE_TGZ  "Enable to build TGZ source packages"  ON)
605
      option(CPACK_SOURCE_TXZ  "Enable to build TXZ source packages"  ON)
606 607
      option(CPACK_SOURCE_TZ   "Enable to build TZ source packages"   ON)
      option(CPACK_SOURCE_ZIP  "Enable to build ZIP source packages"  OFF)
608 609
    endif()
  else()
610
    option(CPACK_SOURCE_7Z  "Enable to build 7-Zip source packages" ON)
611
    option(CPACK_SOURCE_ZIP "Enable to build ZIP source packages" ON)
612
  endif()
613

614
  cpack_optional_append(CPACK_SOURCE_GENERATOR  CPACK_SOURCE_7Z      7Z)
615
  cpack_optional_append(CPACK_SOURCE_GENERATOR  CPACK_SOURCE_CYGWIN  CygwinSource)
616
  cpack_optional_append(CPACK_SOURCE_GENERATOR  CPACK_SOURCE_RPM     RPM)
617
  cpack_optional_append(CPACK_SOURCE_GENERATOR  CPACK_SOURCE_TBZ2    TBZ2)
618
  cpack_optional_append(CPACK_SOURCE_GENERATOR  CPACK_SOURCE_TGZ     TGZ)
619
  cpack_optional_append(CPACK_SOURCE_GENERATOR  CPACK_SOURCE_TXZ     TXZ)
620 621
  cpack_optional_append(CPACK_SOURCE_GENERATOR  CPACK_SOURCE_TZ      TZ)
  cpack_optional_append(CPACK_SOURCE_GENERATOR  CPACK_SOURCE_ZIP     ZIP)
622
endif()
623

624
# mark the above options as advanced
625
mark_as_advanced(
626 627
  CPACK_BINARY_7Z
  CPACK_BINARY_BUNDLE
628
  CPACK_BINARY_CYGWIN
629 630
  CPACK_BINARY_DEB
  CPACK_BINARY_DRAGNDROP
631
  CPACK_BINARY_FREEBSD
632 633
  CPACK_BINARY_IFW
  CPACK_BINARY_NSIS
Alex Turbov's avatar
Alex Turbov committed
634
  CPACK_BINARY_NUGET
635
  CPACK_BINARY_OSXX11
636
  CPACK_BINARY_PACKAGEMAKER
637
  CPACK_BINARY_PRODUCTBUILD
638
  CPACK_BINARY_RPM
639 640
  CPACK_BINARY_STGZ
  CPACK_BINARY_TBZ2
641
  CPACK_BINARY_TGZ
642
  CPACK_BINARY_TXZ
643
  CPACK_BINARY_TZ
644 645
  CPACK_BINARY_WIX
  CPACK_BINARY_ZIP
646
  CPACK_SOURCE_7Z
647
  CPACK_SOURCE_CYGWIN
648
  CPACK_SOURCE_RPM
649 650 651 652 653 654
  CPACK_SOURCE_TBZ2
  CPACK_SOURCE_TGZ
  CPACK_SOURCE_TXZ
  CPACK_SOURCE_TZ
  CPACK_SOURCE_ZIP
  )
655

656
# Set some other variables
657
_cpack_set_default(CPACK_INSTALL_CMAKE_PROJECTS
658
  "${CMAKE_BINARY_DIR};${CMAKE_PROJECT_NAME};ALL;/")
659 660
_cpack_set_default(CPACK_CMAKE_GENERATOR "${CMAKE_GENERATOR}")
_cpack_set_default(CPACK_TOPLEVEL_TAG "${CPACK_SYSTEM_NAME}")
661 662
# if the user has set CPACK_NSIS_DISPLAY_NAME remember it
if(DEFINED CPACK_NSIS_DISPLAY_NAME)
663
  set(CPACK_NSIS_DISPLAY_NAME_SET TRUE)
664 665 666 667
endif()
# if the user has set CPACK_NSIS_DISPLAY
# explicitly, then use that as the default
# value of CPACK_NSIS_PACKAGE_NAME  instead
668
# of CPACK_PACKAGE_INSTALL_DIRECTORY
669
_cpack_set_default(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}")
670 671

if(CPACK_NSIS_DISPLAY_NAME_SET)
672
  _cpack_set_default(CPACK_NSIS_PACKAGE_NAME "${CPACK_NSIS_DISPLAY_NAME}")
673
else()
674
  _cpack_set_default(CPACK_NSIS_PACKAGE_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}")
675
endif()
676

677
_cpack_set_default(CPACK_OUTPUT_CONFIG_FILE
678 679
  "${CMAKE_BINARY_DIR}/CPackConfig.cmake")

680
_cpack_set_default(CPACK_SOURCE_OUTPUT_CONFIG_FILE
681 682
  "${CMAKE_BINARY_DIR}/CPackSourceConfig.cmake")

683 684
_cpack_set_default(CPACK_SET_DESTDIR OFF)
_cpack_set_default(CPACK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
685

686 687
_cpack_set_default(CPACK_NSIS_INSTALLER_ICON_CODE "")
_cpack_set_default(CPACK_NSIS_INSTALLER_MUI_ICON_CODE "")
688

689
# WiX specific variables
690
_cpack_set_default(CPACK_WIX_SIZEOF_VOID_P "${CMAKE_SIZEOF_VOID_P}")
691

692
# set sysroot so SDK tools can be used
693
if(CMAKE_OSX_SYSROOT)
694
  _cpack_set_default(CPACK_OSX_SYSROOT "${_CMAKE_OSX_SYSROOT_PATH}")
695 696
endif()

697 698
_cpack_set_default(CPACK_BUILD_SOURCE_DIRS "${CMAKE_SOURCE_DIR};${CMAKE_BINARY_DIR}")

699 700 701 702
if(DEFINED CPACK_COMPONENTS_ALL)
  if(CPACK_MONOLITHIC_INSTALL)
    message("CPack warning: both CPACK_COMPONENTS_ALL and CPACK_MONOLITHIC_INSTALL have been set.\nDefaulting to a monolithic installation.")
    set(CPACK_COMPONENTS_ALL)
703
  else()
704 705
    # The user has provided the set of components to be installed as
    # part of a component-based installation; trust her.
706
    set(CPACK_COMPONENTS_ALL_SET_BY_USER TRUE)
707 708
  endif()
else()
709 710 711
  # If the user has not specifically requested a monolithic installer
  # but has specified components in various "install" commands, tell
  # CPack about those components.
712 713 714 715
  if(NOT CPACK_MONOLITHIC_INSTALL)
    get_cmake_property(CPACK_COMPONENTS_ALL COMPONENTS)
    list(LENGTH CPACK_COMPONENTS_ALL CPACK_COMPONENTS_LEN)
    if(CPACK_COMPONENTS_LEN EQUAL 1)
716 717 718
      # Only one component: this is not a component-based installation
      # (at least, it isn't a component-based installation, but may
      # become one later if the user uses the cpack_add_* commands).
719
      set(CPACK_COMPONENTS_ALL)
720
    endif()
721
    set(CPACK_COMPONENTS_LEN)
722 723
  endif()
endif()
724 725 726 727 728 729 730 731

# CMake always generates a component named "Unspecified", which is
# used to install everything that doesn't have an explicitly-provided
# component. Since these files should always be installed, we'll make
# them hidden and required.
set(CPACK_COMPONENT_UNSPECIFIED_HIDDEN TRUE)
set(CPACK_COMPONENT_UNSPECIFIED_REQUIRED TRUE)

Bill Hoffman's avatar
Bill Hoffman committed
732
cpack_encode_variables()
733
configure_file("${cpack_input_file}" "${CPACK_OUTPUT_CONFIG_FILE}" @ONLY)
734

735
# Generate source file
736
_cpack_set_default(CPACK_SOURCE_INSTALLED_DIRECTORIES
737
  "${CMAKE_SOURCE_DIR};/")
738 739
_cpack_set_default(CPACK_SOURCE_TOPLEVEL_TAG "${CPACK_SYSTEM_NAME}-Source")
_cpack_set_default(CPACK_SOURCE_PACKAGE_FILE_NAME
740
  "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Source")
741 742 743 744 745 746 747 748 749

set(__cpack_source_ignore_files_default
  "/CVS/;/\\.svn/;/\\.bzr/;/\\.hg/;/\\.git/;\\.swp$;\\.#;/#")
if(NOT CPACK_VERBATIM_VARIABLES)
  _cpack_escape_for_cmake(__cpack_source_ignore_files_default
    "${__cpack_source_ignore_files_default}")
endif()
_cpack_set_default(CPACK_SOURCE_IGNORE_FILES "${__cpack_source_ignore_files_default}")

750 751 752 753 754 755 756
set(CPACK_INSTALL_CMAKE_PROJECTS "${CPACK_SOURCE_INSTALL_CMAKE_PROJECTS}")
set(CPACK_INSTALLED_DIRECTORIES "${CPACK_SOURCE_INSTALLED_DIRECTORIES}")
set(CPACK_GENERATOR "${CPACK_SOURCE_GENERATOR}")
set(CPACK_TOPLEVEL_TAG "${CPACK_SOURCE_TOPLEVEL_TAG}")
set(CPACK_PACKAGE_FILE_NAME "${CPACK_SOURCE_PACKAGE_FILE_NAME}")
set(CPACK_IGNORE_FILES "${CPACK_SOURCE_IGNORE_FILES}")
set(CPACK_STRIP_FILES "${CPACK_SOURCE_STRIP_FILES}")
757

758 759
set(CPACK_RPM_PACKAGE_SOURCES "ON")

760
cpack_encode_variables()
761
configure_file("${cpack_source_input_file}"
762
  "${CPACK_SOURCE_OUTPUT_CONFIG_FILE}" @ONLY)