Packaging with CPack
Introduction
CPack is a tool that comes bundled with CMake. It allows you to create platform-specific packages for your project, such as:
.dmg
: Disk Image (common on macOS)..tar.gz
: Compressed archive (common on Unix-like systems)..zip
: Compressed archive (common on Windows).
Key Concepts
install()
: Specifies files or targets to include in the package.include(CPack)
: Enables CPack and generates packaging targets.- CPack Generators: Specify the type of package to create (e.g.,
DragNDrop
for.dmg
).
Code Sample
Let’s create a simple project and package it for macOS.
- Update your
CMakeLists.txt
:
- Write
main.cpp
- Build and package the project:
Output:
- Check the generated packages
HelloWorld-1.0.0-Darwin.dmg
: A macOS disk imageHelloWorld-1.0.0-Darwin.tar.gz
: A compressed archive.