Packaging Debug and Release.rst 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. Step 12: Packaging Debug and Release
  2. ====================================
  3. **Note:** This example is valid for single-configuration generators and will
  4. not work for multi-configuration generators (e.g. Visual Studio).
  5. By default, CMake's model is that a build directory only contains a single
  6. configuration, be it Debug, Release, MinSizeRel, or RelWithDebInfo. It is
  7. possible, however, to setup CPack to bundle multiple build directories and
  8. construct a package that contains multiple configurations of the same project.
  9. First, we want to ensure that the debug and release builds use different names
  10. for the executables and libraries that will be installed. Let's use `d` as the
  11. postfix for the debug executable and libraries.
  12. Set :variable:`CMAKE_DEBUG_POSTFIX` near the beginning of the top-level
  13. ``CMakeLists.txt`` file:
  14. .. literalinclude:: Complete/CMakeLists.txt
  15. :language: cmake
  16. :start-after: project(Tutorial VERSION 1.0)
  17. :end-before: target_compile_features(tutorial_compiler_flags
  18. And the :prop_tgt:`DEBUG_POSTFIX` property on the tutorial executable:
  19. .. literalinclude:: Complete/CMakeLists.txt
  20. :language: cmake
  21. :start-after: # add the executable
  22. :end-before: # add the binary tree to the search path for include files
  23. Let's also add version numbering to the MathFunctions library. In
  24. ``MathFunctions/CMakeLists.txt``, set the :prop_tgt:`VERSION` and
  25. :prop_tgt:`SOVERSION` properties:
  26. .. literalinclude:: Complete/MathFunctions/CMakeLists.txt
  27. :language: cmake
  28. :start-after: # setup the version numbering
  29. :end-before: # install rules
  30. From the ``Step12`` directory, create ``debug`` and ``release``
  31. subbdirectories. The layout will look like:
  32. .. code-block:: none
  33. - Step12
  34. - debug
  35. - release
  36. Now we need to setup debug and release builds. We can use
  37. :variable:`CMAKE_BUILD_TYPE` to set the configuration type:
  38. .. code-block:: console
  39. cd debug
  40. cmake -DCMAKE_BUILD_TYPE=Debug ..
  41. cmake --build .
  42. cd ../release
  43. cmake -DCMAKE_BUILD_TYPE=Release ..
  44. cmake --build .
  45. Now that both the debug and release builds are complete, we can use a custom
  46. configuration file to package both builds into a single release. In the
  47. ``Step12`` directory, create a file called ``MultiCPackConfig.cmake``. In this
  48. file, first include the default configuration file that was created by the
  49. :manual:`cmake <cmake(1)>` executable.
  50. Next, use the ``CPACK_INSTALL_CMAKE_PROJECTS`` variable to specify which
  51. projects to install. In this case, we want to install both debug and release.
  52. .. literalinclude:: Complete/MultiCPackConfig.cmake
  53. :language: cmake
  54. From the ``Step12`` directory, run :manual:`cpack <cpack(1)>` specifying our
  55. custom configuration file with the ``config`` option:
  56. .. code-block:: console
  57. cpack --config MultiCPackConfig.cmake