Packaging Debug and Release.rst 3.0 KB

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