Packaging Debug and Release.rst 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. :caption: CMakeLists.txt
  16. :language: cmake
  17. :start-after: project(Tutorial VERSION 1.0)
  18. :end-before: target_compile_features(tutorial_compiler_flags
  19. And the :prop_tgt:`DEBUG_POSTFIX` property on the tutorial executable:
  20. .. literalinclude:: Complete/CMakeLists.txt
  21. :caption: CMakeLists.txt
  22. :language: cmake
  23. :start-after: # add the executable
  24. :end-before: # add the binary tree to the search path for include files
  25. Let's also add version numbering to the ``MathFunctions`` library. In
  26. ``MathFunctions/CMakeLists.txt``, set the :prop_tgt:`VERSION` and
  27. :prop_tgt:`SOVERSION` properties:
  28. .. literalinclude:: Complete/MathFunctions/CMakeLists.txt
  29. :caption: MathFunctions/CMakeLists.txt
  30. :language: cmake
  31. :start-after: # setup the version numbering
  32. :end-before: # install rules
  33. From the ``Step12`` directory, create ``debug`` and ``release``
  34. subbdirectories. The layout will look like:
  35. .. code-block:: none
  36. - Step12
  37. - debug
  38. - release
  39. Now we need to setup debug and release builds. We can use
  40. :variable:`CMAKE_BUILD_TYPE` to set the configuration type:
  41. .. code-block:: console
  42. cd debug
  43. cmake -DCMAKE_BUILD_TYPE=Debug ..
  44. cmake --build .
  45. cd ../release
  46. cmake -DCMAKE_BUILD_TYPE=Release ..
  47. cmake --build .
  48. Now that both the debug and release builds are complete, we can use a custom
  49. configuration file to package both builds into a single release. In the
  50. ``Step12`` directory, create a file called ``MultiCPackConfig.cmake``. In this
  51. file, first include the default configuration file that was created by the
  52. :manual:`cmake <cmake(1)>` executable.
  53. Next, use the ``CPACK_INSTALL_CMAKE_PROJECTS`` variable to specify which
  54. projects to install. In this case, we want to install both debug and release.
  55. .. literalinclude:: Complete/MultiCPackConfig.cmake
  56. :caption: MultiCPackConfig.cmake
  57. :language: cmake
  58. From the ``Step12`` directory, run :manual:`cpack <cpack(1)>` specifying our
  59. custom configuration file with the ``config`` option:
  60. .. code-block:: console
  61. cpack --config MultiCPackConfig.cmake