0ee5db2acaea51b21b23dc364f98238bb30b0c01
[platform/upstream/cmake.git] / Help / guide / tutorial / Packaging an Installer.rst
1 Step 7: Packaging an Installer
2 ==============================
3
4 Next suppose that we want to distribute our project to other people so that
5 they can use it. We want to provide both binary and source distributions on a
6 variety of platforms. This is a little different from the install we did
7 previously in :guide:`tutorial/Installing and Testing`, where we were
8 installing the binaries that we had built from the source code. In this
9 example we will be building installation packages that support binary
10 installations and package management features. To accomplish this we will use
11 CPack to create platform specific installers. Specifically we need to add a
12 few lines to the bottom of our top-level ``CMakeLists.txt`` file.
13
14 .. literalinclude:: Step8/CMakeLists.txt
15   :caption: CMakeLists.txt
16   :name: CMakeLists.txt-include-CPack
17   :language: cmake
18   :start-after: # setup installer
19
20 That is all there is to it. We start by including
21 :module:`InstallRequiredSystemLibraries`. This module will include any runtime
22 libraries that are needed by the project for the current platform. Next we set
23 some CPack variables to where we have stored the license and version
24 information for this project. The version information was set earlier in this
25 tutorial and the ``License.txt`` has been included in the top-level source
26 directory for this step.  The :variable:`CPACK_SOURCE_GENERATOR` variable
27 selects a file format for the source package.
28
29 Finally we include the :module:`CPack module <CPack>` which will use these
30 variables and some other properties of the current system to setup an
31 installer.
32
33 The next step is to build the project in the usual manner and then run the
34 :manual:`cpack <cpack(1)>` executable. To build a binary distribution, from the
35 binary directory run:
36
37 .. code-block:: console
38
39   cpack
40
41 To specify the generator, use the ``-G`` option. For multi-config builds, use
42 ``-C`` to specify the configuration. For example:
43
44 .. code-block:: console
45
46   cpack -G ZIP -C Debug
47
48 For a list of available generators, see :manual:`cpack-generators(7)` or call
49 ``cpack --help``. An :cpack_gen:`archive generator <CPack Archive Generator>`
50 like ZIP creates a compressed archive of all *installed* files.
51
52 To create an archive of the *full* source tree you would type:
53
54 .. code-block:: console
55
56   cpack --config CPackSourceConfig.cmake
57
58 Alternatively, run ``make package`` or right click the ``Package`` target and
59 ``Build Project`` from an IDE.
60
61 Run the installer found in the binary directory. Then run the installed
62 executable and verify that it works.