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