CPack.cmake 28.4 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 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
#[=======================================================================[.rst:
CPack
-----

Build binary and source package installers.

Variables common to all CPack generators
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The
CPack module generates binary and source installers in a variety of
formats using the cpack program.  Inclusion of the CPack module adds
two new targets to the resulting makefiles, package and
package_source, which build the binary and source installers,
respectively.  The generated binary installers contain everything
installed via CMake's INSTALL command (and the deprecated
INSTALL_FILES, INSTALL_PROGRAMS, and INSTALL_TARGETS commands).

For certain kinds of binary installers (including the graphical
installers on Mac OS X and Windows), CPack generates installers that
allow users to select individual application components to install.
See CPackComponent module for that.

The CPACK_GENERATOR variable has different meanings in different
contexts.  In your CMakeLists.txt file, CPACK_GENERATOR is a *list of
generators*: when run with no other arguments, CPack will iterate over
that list and produce one package for each generator.  In a
CPACK_PROJECT_CONFIG_FILE, though, 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
CPACK_PROJECT_CONFIG_FILE.

The CMake source tree itself contains a CPACK_PROJECT_CONFIG_FILE.
See the top level file CMakeCPackOptions.cmake.in for an example.

If set, the CPACK_PROJECT_CONFIG_FILE is included automatically on a
per-generator basis.  It only need contain overrides.

Here's how it works:

* cpack runs
* it includes CPackConfig.cmake
* 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
  the CPACK_GENERATOR variable set in the CPackConfig.cmake input file.
* foreach generator, it then

  - sets CPACK_GENERATOR to the one currently being iterated
  - includes the CPACK_PROJECT_CONFIG_FILE
  - produces the package for that generator

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

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

.. variable:: CPACK_PACKAGE_NAME

 The name of the package (or application). If not specified, defaults to
 the project name.

.. variable:: CPACK_PACKAGE_VENDOR

 The name of the package vendor. (e.g., "Kitware"). Default is "Humanity".

.. variable:: CPACK_PACKAGE_DIRECTORY

 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 CPack config file or from the cpack command line option
 "-B". If set the command line option override the value found in the
 config file.

.. variable:: CPACK_PACKAGE_VERSION_MAJOR

 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.

.. variable:: CPACK_PACKAGE_VERSION_MINOR

 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.

.. variable:: CPACK_PACKAGE_VERSION_PATCH

 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.

.. variable:: CPACK_PACKAGE_DESCRIPTION_FILE

 A text file used to describe the project. Used, for example, the
 introduction screen of a CPack-generated Windows installer to describe
 the project.

.. variable:: CPACK_PACKAGE_DESCRIPTION_SUMMARY

 Short description of the project (only a few words). Default value is::

   ${CMAKE_PROJECT_DESCRIPTION}

 if DESCRIPTION has given to the project() call or
 CMake generated string with PROJECT_NAME otherwise.

.. variable:: CPACK_PACKAGE_HOMEPAGE_URL

 Project homepage URL. Default value is::

   ${CMAKE_PROJECT_HOMEPAGE_URL}

 if HOMEPAGE_URL has given to the project().

.. variable:: CPACK_PACKAGE_FILE_NAME

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

  ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}.

.. variable:: CPACK_PACKAGE_INSTALL_DIRECTORY

 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 element will be
 put inside this directory.

.. variable:: CPACK_PACKAGE_ICON

 A branding image that will be displayed inside the installer (used by GUI
 installers).

.. variable:: CPACK_PACKAGE_CHECKSUM

 An algorithm that will be used to generate additional file with checksum
 of the package. Output file name will be::

    ${CPACK_PACKAGE_FILE_NAME}.${CPACK_PACKAGE_CHECKSUM}

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

.. variable:: CPACK_PROJECT_CONFIG_FILE

 CPack-time project CPack configuration file. This file included at cpack
 time, once per generator after CPack has set CPACK_GENERATOR to the
 actual generator being used. It allows per-generator setting of CPACK_*
 variables at cpack time.

.. variable:: CPACK_RESOURCE_FILE_LICENSE

 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 installed file 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 INSTALL
 command in your CMakeLists.txt.

.. variable:: CPACK_RESOURCE_FILE_README

 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 uses this file.

.. variable:: CPACK_RESOURCE_FILE_WELCOME

 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.

.. variable:: CPACK_MONOLITHIC_INSTALL

 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 1/TRUE.

.. variable:: CPACK_GENERATOR

 List of CPack generators to use.  If not specified, CPack will create a
 set of options 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.

.. variable:: CPACK_OUTPUT_CONFIG_FILE

 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.

.. variable:: CPACK_PACKAGE_EXECUTABLES

 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).

.. variable:: CPACK_STRIP_FILES

 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).

.. variable:: CPACK_VERBATIM_VARIABLES

 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.

 * Mandatory : NO
 * Default   : FALSE

The following CPack variables are specific to source packages, and
will not affect binary packages:

.. variable:: CPACK_SOURCE_PACKAGE_FILE_NAME

 The name of the source package. For example cmake-2.6.1.

.. variable:: CPACK_SOURCE_STRIP_FILES

 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).

.. variable:: CPACK_SOURCE_GENERATOR

 List of generators used for the source packages. As with 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.

.. variable:: CPACK_SOURCE_OUTPUT_CONFIG_FILE

 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.

.. variable:: CPACK_SOURCE_IGNORE_FILES

 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.*

The following variables are for advanced uses of CPack:

.. variable:: CPACK_CMAKE_GENERATOR

 What CMake generator should be used if the project is CMake
 project. Defaults to the value of CMAKE_GENERATOR few users will want to
 change this setting.

.. variable:: CPACK_INSTALL_CMAKE_PROJECTS

 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.

.. variable:: CPACK_SYSTEM_NAME

 System name, defaults to the value of ${CMAKE_SYSTEM_NAME}, except on
 Windows where it will be "win32" or "win64".

.. variable:: CPACK_PACKAGE_VERSION

 Package full version, used internally. By default, this is built from
 CPACK_PACKAGE_VERSION_MAJOR, CPACK_PACKAGE_VERSION_MINOR, and
 CPACK_PACKAGE_VERSION_PATCH.

.. variable:: CPACK_TOPLEVEL_TAG

 Directory for the installed files.

.. variable:: CPACK_INSTALL_COMMANDS

 Extra commands to install components.

.. variable:: CPACK_INSTALLED_DIRECTORIES

 Extra directories to install.

.. variable:: CPACK_PACKAGE_INSTALL_REGISTRY_KEY

 Registry key used when installing this project. This is only used by
 installer for Windows.  The default value is based on the installation
 directory.

.. variable:: CPACK_CREATE_DESKTOP_LINKS

 List of desktop links to create.
 Each desktop link requires a corresponding start menu shortcut
 as created by :variable:`CPACK_PACKAGE_EXECUTABLES`.
324 325 326 327 328 329 330

.. variable:: CPACK_BINARY_<GENNAME>

 CPack generated options for binary generators. The CPack.cmake module
 generates (when CPACK_GENERATOR is not set) a set of CMake options (see
 CMake option command) which may then be used to select the CPack
 generator(s) to be used when launching the package target.
331
#]=======================================================================]
332

333
# Define this var in order to avoid (or warn) concerning multiple inclusion
334 335
if(CPack_CMake_INCLUDED)
  message(WARNING "CPack.cmake has already been included!!")
336
else()
337
  set(CPack_CMake_INCLUDED 1)
338
endif()
339

340
# Pick a configuration file
341 342 343
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")
344
endif()
345 346 347
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")
348
endif()
349

350 351 352
# Backward compatibility
# Include CPackComponent macros if it has not already been included before.
include(CPackComponent)
353

354
# Macro for setting values if a user did not overwrite them
355
# Mangles CMake-special characters. Only kept for backwards compatibility.
356
macro(cpack_set_if_not_set name value)
357 358
  message(DEPRECATION "cpack_set_if_not_set is obsolete; do not use.")
  _cpack_set_default("${name}" "${value}")
359
endmacro()
360

361
# cpack_encode_variables - Function to encode variables for the configuration file
362
# find any variable that starts with CPACK and create a variable
Bill Hoffman's avatar
Bill Hoffman committed
363 364 365
# _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.
366 367
function(cpack_encode_variables)
  set(commands "")
368 369
  get_cmake_property(res VARIABLES)
  foreach(var ${res})
370
    if(var MATCHES "^CPACK")
371 372 373 374
      if(CPACK_VERBATIM_VARIABLES)
        _cpack_escape_for_cmake(value "${${var}}")
      else()
        set(value "${${var}}")
375
      endif()
376

377
      string(APPEND commands "\nset(${var} \"${value}\")")
378
    endif()
379
  endforeach()
380 381 382

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

384 385 386 387 388 389 390
# Internal use functions
function(_cpack_set_default name value)
  if(NOT DEFINED "${name}")
    set("${name}" "${value}" PARENT_SCOPE)
  endif()
endfunction()

391 392 393 394 395
function(_cpack_escape_for_cmake var value)
  string(REGEX REPLACE "([\\\$\"])" "\\\\\\1" escaped "${value}")
  set("${var}" "${escaped}" PARENT_SCOPE)
endfunction()

396
# Set the package name
397
_cpack_set_default(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
398
if(CMAKE_PROJECT_VERSION_MAJOR)
Craig Scott's avatar
Craig Scott committed
399 400 401 402 403 404 405
  _cpack_set_default(CPACK_PACKAGE_VERSION_MAJOR "${CMAKE_PROJECT_VERSION_MAJOR}")
  if(CMAKE_PROJECT_VERSION_MINOR)
    _cpack_set_default(CPACK_PACKAGE_VERSION_MINOR "${CMAKE_PROJECT_VERSION_MINOR}")
    if(CMAKE_PROJECT_VERSION_PATCH)
      _cpack_set_default(CPACK_PACKAGE_VERSION_PATCH "${CMAKE_PROJECT_VERSION_PATCH}")
      _cpack_set_default(CPACK_PACKAGE_VERSION
        "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
406
    else()
Craig Scott's avatar
Craig Scott committed
407 408
      _cpack_set_default(CPACK_PACKAGE_VERSION
      "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
409
    endif()
Craig Scott's avatar
Craig Scott committed
410 411 412
  else()
    _cpack_set_default(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}")
  endif()
413
else()
Craig Scott's avatar
Craig Scott committed
414 415 416 417 418
  _cpack_set_default(CPACK_PACKAGE_VERSION_MAJOR "0")
  _cpack_set_default(CPACK_PACKAGE_VERSION_MINOR "1")
  _cpack_set_default(CPACK_PACKAGE_VERSION_PATCH "1")
  _cpack_set_default(CPACK_PACKAGE_VERSION
    "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
419
endif()
420
_cpack_set_default(CPACK_PACKAGE_VENDOR "Humanity")
421 422 423 424 425 426 427
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()
428 429 430 431
if(CMAKE_PROJECT_HOMEPAGE_URL)
  _cpack_set_default(CPACK_PACKAGE_HOMEPAGE_URL
    "${CMAKE_PROJECT_HOMEPAGE_URL}")
endif()
432

433
_cpack_set_default(CPACK_PACKAGE_DESCRIPTION_FILE
Andy Cedilnik's avatar
Andy Cedilnik committed
434
  "${CMAKE_ROOT}/Templates/CPack.GenericDescription.txt")
435
_cpack_set_default(CPACK_RESOURCE_FILE_LICENSE
436
  "${CMAKE_ROOT}/Templates/CPack.GenericLicense.txt")
437
_cpack_set_default(CPACK_RESOURCE_FILE_README
438
  "${CMAKE_ROOT}/Templates/CPack.GenericDescription.txt")
439
_cpack_set_default(CPACK_RESOURCE_FILE_WELCOME
440
  "${CMAKE_ROOT}/Templates/CPack.GenericWelcome.txt")
441

442
_cpack_set_default(CPACK_MODULE_PATH "${CMAKE_MODULE_PATH}")
443

444 445 446 447 448 449
# 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()

450 451
if(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL)
  set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
452
endif()
453 454 455

if(CPACK_NSIS_MODIFY_PATH)
  set(CPACK_NSIS_MODIFY_PATH ON)
456
endif()
457 458

set(__cpack_system_name ${CMAKE_SYSTEM_NAME})
459 460
if(__cpack_system_name MATCHES "Windows")
  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
461
    set(__cpack_system_name win64)
462
  else()
463
    set(__cpack_system_name win32)
464 465
  endif()
endif()
466
_cpack_set_default(CPACK_SYSTEM_NAME "${__cpack_system_name}")
467

468 469
# Root dir: default value should be the string literal "$PROGRAMFILES"
# for backwards compatibility. Projects may set this value to anything.
470 471 472 473 474 475
# 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()
476
_cpack_set_default(CPACK_NSIS_INSTALL_ROOT "${__cpack_root_default}")
477

478
# <project>-<major>.<minor>.<patch>-<release>-<platform>.<pkgtype>
479
_cpack_set_default(CPACK_PACKAGE_FILE_NAME
480
  "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}")
481
_cpack_set_default(CPACK_PACKAGE_INSTALL_DIRECTORY
Andy Cedilnik's avatar
Andy Cedilnik committed
482
  "${CPACK_PACKAGE_NAME} ${CPACK_PACKAGE_VERSION}")
483
_cpack_set_default(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
484
  "${CPACK_PACKAGE_INSTALL_DIRECTORY}")
485 486
_cpack_set_default(CPACK_PACKAGE_DEFAULT_LOCATION "/")
_cpack_set_default(CPACK_PACKAGE_RELOCATABLE "true")
487 488 489 490

# always force to exactly "true" or "false" for CPack.Info.plist.in:
if(CPACK_PACKAGE_RELOCATABLE)
  set(CPACK_PACKAGE_RELOCATABLE "true")
491
else()
492
  set(CPACK_PACKAGE_RELOCATABLE "false")
493
endif()
494

Alexander Neundorf's avatar
 
Alexander Neundorf committed
495 496 497
macro(cpack_check_file_exists file description)
  if(NOT EXISTS "${file}")
    message(SEND_ERROR "CPack ${description} file: \"${file}\" could not be found.")
498 499
  endif()
endmacro()
Alexander Neundorf's avatar
 
Alexander Neundorf committed
500

501 502 503 504
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")
505

Alexander Neundorf's avatar
 
Alexander Neundorf committed
506 507 508
macro(cpack_optional_append _list _cond _item)
  if(${_cond})
    set(${_list} ${${_list}} ${_item})
509 510
  endif()
endmacro()
Alexander Neundorf's avatar
 
Alexander Neundorf committed
511

512 513 514
# 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.
Alexander Neundorf's avatar
 
Alexander Neundorf committed
515 516 517
if(NOT CPACK_GENERATOR)
  if(UNIX)
    if(CYGWIN)
518
      option(CPACK_BINARY_CYGWIN "Enable to build Cygwin binary packages" ON)
519
    else()
Alexander Neundorf's avatar
 
Alexander Neundorf committed
520
      if(APPLE)
521
        option(CPACK_BINARY_BUNDLE       "Enable to build OSX bundles"      OFF)
522
        option(CPACK_BINARY_DRAGNDROP    "Enable to build OSX Drag And Drop package" OFF)
523
        option(CPACK_BINARY_OSXX11       "Enable to build OSX X11 packages"      OFF)
524
        option(CPACK_BINARY_PACKAGEMAKER "Enable to build PackageMaker packages" OFF)
525
        option(CPACK_BINARY_PRODUCTBUILD "Enable to build productbuild packages" OFF)
526
      else()
527
        option(CPACK_BINARY_TZ  "Enable to build TZ packages"     ON)
528
      endif()
529
      option(CPACK_BINARY_DEB  "Enable to build Debian packages"  OFF)
530
      option(CPACK_BINARY_FREEBSD  "Enable to build FreeBSD packages"  OFF)
531 532
      option(CPACK_BINARY_NSIS "Enable to build NSIS packages"    OFF)
      option(CPACK_BINARY_RPM  "Enable to build RPM packages"     OFF)
533
      option(CPACK_BINARY_STGZ "Enable to build STGZ packages"    ON)
534
      option(CPACK_BINARY_TBZ2 "Enable to build TBZ2 packages"    OFF)
535
      option(CPACK_BINARY_TGZ  "Enable to build TGZ packages"     ON)
536
      option(CPACK_BINARY_TXZ  "Enable to build TXZ packages"     OFF)
537 538
    endif()
  else()
539
    option(CPACK_BINARY_7Z   "Enable to build 7-Zip packages" OFF)
540
    option(CPACK_BINARY_NSIS "Enable to build NSIS packages" ON)
541
    option(CPACK_BINARY_WIX  "Enable to build WiX packages" OFF)
542
    option(CPACK_BINARY_ZIP  "Enable to build ZIP packages" OFF)
543
  endif()
544
  option(CPACK_BINARY_IFW "Enable to build IFW packages" OFF)
545

546
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_7Z           7Z)
547
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_BUNDLE       Bundle)
548 549
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_CYGWIN       CygwinBinary)
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_DEB          DEB)
550
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_DRAGNDROP    DragNDrop)
551
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_FREEBSD      FREEBSD)
552
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_IFW          IFW)
553
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_NSIS         NSIS)
554 555
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_OSXX11       OSXX11)
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_PACKAGEMAKER PackageMaker)
556
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_PRODUCTBUILD productbuild)
557
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_RPM          RPM)
558 559
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_STGZ         STGZ)
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_TBZ2         TBZ2)
560
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_TGZ          TGZ)
561
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_TXZ          TXZ)
562
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_TZ           TZ)
563
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_WIX          WIX)
564
  cpack_optional_append(CPACK_GENERATOR  CPACK_BINARY_ZIP          ZIP)
565

566
endif()
Alexander Neundorf's avatar
 
Alexander Neundorf committed
567 568 569 570 571 572

# 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)
573
    else()
574
      option(CPACK_SOURCE_RPM  "Enable to build RPM source packages"  OFF)
Alexander Neundorf's avatar
 
Alexander Neundorf committed
575 576
      option(CPACK_SOURCE_TBZ2 "Enable to build TBZ2 source packages" ON)
      option(CPACK_SOURCE_TGZ  "Enable to build TGZ source packages"  ON)
577
      option(CPACK_SOURCE_TXZ  "Enable to build TXZ source packages"  ON)
Alexander Neundorf's avatar
 
Alexander Neundorf committed
578 579
      option(CPACK_SOURCE_TZ   "Enable to build TZ source packages"   ON)
      option(CPACK_SOURCE_ZIP  "Enable to build ZIP source packages"  OFF)
580 581
    endif()
  else()
582
    option(CPACK_SOURCE_7Z  "Enable to build 7-Zip source packages" ON)
583
    option(CPACK_SOURCE_ZIP "Enable to build ZIP source packages" ON)
584
  endif()
Alexander Neundorf's avatar
 
Alexander Neundorf committed
585

586
  cpack_optional_append(CPACK_SOURCE_GENERATOR  CPACK_SOURCE_7Z      7Z)
Alexander Neundorf's avatar
 
Alexander Neundorf committed
587
  cpack_optional_append(CPACK_SOURCE_GENERATOR  CPACK_SOURCE_CYGWIN  CygwinSource)
588
  cpack_optional_append(CPACK_SOURCE_GENERATOR  CPACK_SOURCE_RPM     RPM)
Alexander Neundorf's avatar
 
Alexander Neundorf committed
589
  cpack_optional_append(CPACK_SOURCE_GENERATOR  CPACK_SOURCE_TBZ2    TBZ2)
590
  cpack_optional_append(CPACK_SOURCE_GENERATOR  CPACK_SOURCE_TGZ     TGZ)
591
  cpack_optional_append(CPACK_SOURCE_GENERATOR  CPACK_SOURCE_TXZ     TXZ)
Alexander Neundorf's avatar
 
Alexander Neundorf committed
592 593
  cpack_optional_append(CPACK_SOURCE_GENERATOR  CPACK_SOURCE_TZ      TZ)
  cpack_optional_append(CPACK_SOURCE_GENERATOR  CPACK_SOURCE_ZIP     ZIP)
594
endif()
595

Alexander Neundorf's avatar
 
Alexander Neundorf committed
596
# mark the above options as advanced
597
mark_as_advanced(
598 599
  CPACK_BINARY_7Z
  CPACK_BINARY_BUNDLE
600
  CPACK_BINARY_CYGWIN
601 602
  CPACK_BINARY_DEB
  CPACK_BINARY_DRAGNDROP
603
  CPACK_BINARY_FREEBSD
604 605
  CPACK_BINARY_IFW
  CPACK_BINARY_NSIS
606
  CPACK_BINARY_OSXX11
607
  CPACK_BINARY_PACKAGEMAKER
608
  CPACK_BINARY_PRODUCTBUILD
609
  CPACK_BINARY_RPM
610 611
  CPACK_BINARY_STGZ
  CPACK_BINARY_TBZ2
612
  CPACK_BINARY_TGZ
613
  CPACK_BINARY_TXZ
614
  CPACK_BINARY_TZ
615 616
  CPACK_BINARY_WIX
  CPACK_BINARY_ZIP
617
  CPACK_SOURCE_7Z
618
  CPACK_SOURCE_CYGWIN
619
  CPACK_SOURCE_RPM
620 621 622 623 624 625
  CPACK_SOURCE_TBZ2
  CPACK_SOURCE_TGZ
  CPACK_SOURCE_TXZ
  CPACK_SOURCE_TZ
  CPACK_SOURCE_ZIP
  )
Alexander Neundorf's avatar
 
Alexander Neundorf committed
626

627
# Set some other variables
628
_cpack_set_default(CPACK_INSTALL_CMAKE_PROJECTS
629
  "${CMAKE_BINARY_DIR};${CMAKE_PROJECT_NAME};ALL;/")
630 631
_cpack_set_default(CPACK_CMAKE_GENERATOR "${CMAKE_GENERATOR}")
_cpack_set_default(CPACK_TOPLEVEL_TAG "${CPACK_SYSTEM_NAME}")
632 633
# if the user has set CPACK_NSIS_DISPLAY_NAME remember it
if(DEFINED CPACK_NSIS_DISPLAY_NAME)
634
  set(CPACK_NSIS_DISPLAY_NAME_SET TRUE)
635 636 637 638
endif()
# if the user has set CPACK_NSIS_DISPLAY
# explicitly, then use that as the default
# value of CPACK_NSIS_PACKAGE_NAME  instead
639
# of CPACK_PACKAGE_INSTALL_DIRECTORY
640
_cpack_set_default(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}")
641 642

if(CPACK_NSIS_DISPLAY_NAME_SET)
643
  _cpack_set_default(CPACK_NSIS_PACKAGE_NAME "${CPACK_NSIS_DISPLAY_NAME}")
644
else()
645
  _cpack_set_default(CPACK_NSIS_PACKAGE_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}")
646
endif()
647

648
_cpack_set_default(CPACK_OUTPUT_CONFIG_FILE
649 650
  "${CMAKE_BINARY_DIR}/CPackConfig.cmake")

651
_cpack_set_default(CPACK_SOURCE_OUTPUT_CONFIG_FILE
652 653
  "${CMAKE_BINARY_DIR}/CPackSourceConfig.cmake")

654 655
_cpack_set_default(CPACK_SET_DESTDIR OFF)
_cpack_set_default(CPACK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
656

657 658
_cpack_set_default(CPACK_NSIS_INSTALLER_ICON_CODE "")
_cpack_set_default(CPACK_NSIS_INSTALLER_MUI_ICON_CODE "")
659

660
# WiX specific variables
661
_cpack_set_default(CPACK_WIX_SIZEOF_VOID_P "${CMAKE_SIZEOF_VOID_P}")
662

663
# set sysroot so SDK tools can be used
664
if(CMAKE_OSX_SYSROOT)
665
  _cpack_set_default(CPACK_OSX_SYSROOT "${_CMAKE_OSX_SYSROOT_PATH}")
666 667
endif()

668 669
_cpack_set_default(CPACK_BUILD_SOURCE_DIRS "${CMAKE_SOURCE_DIR};${CMAKE_BINARY_DIR}")

670 671 672 673
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)
674
  else()
675 676
    # The user has provided the set of components to be installed as
    # part of a component-based installation; trust her.
677
    set(CPACK_COMPONENTS_ALL_SET_BY_USER TRUE)
678 679
  endif()
else()
680 681 682
  # If the user has not specifically requested a monolithic installer
  # but has specified components in various "install" commands, tell
  # CPack about those components.
683 684 685 686
  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)
687 688 689
      # 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).
690
      set(CPACK_COMPONENTS_ALL)
691
    endif()
692
    set(CPACK_COMPONENTS_LEN)
693 694
  endif()
endif()
695 696 697 698 699 700 701 702

# 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
703
cpack_encode_variables()
704
configure_file("${cpack_input_file}" "${CPACK_OUTPUT_CONFIG_FILE}" @ONLY)
705

706
# Generate source file
707
_cpack_set_default(CPACK_SOURCE_INSTALLED_DIRECTORIES
708
  "${CMAKE_SOURCE_DIR};/")
709 710
_cpack_set_default(CPACK_SOURCE_TOPLEVEL_TAG "${CPACK_SYSTEM_NAME}-Source")
_cpack_set_default(CPACK_SOURCE_PACKAGE_FILE_NAME
711
  "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Source")
712 713 714 715 716 717 718 719 720

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}")

721 722 723 724 725 726 727
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}")
728

729 730
set(CPACK_RPM_PACKAGE_SOURCES "ON")

731
cpack_encode_variables()
Alexander Neundorf's avatar
 
Alexander Neundorf committed
732
configure_file("${cpack_source_input_file}"
733
  "${CPACK_SOURCE_OUTPUT_CONFIG_FILE}" @ONLY)