1
0

Packaging an Installer.rst 2.1 KB

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