cpack: Usage, Options & Common CI Errors
cpack turns an installed CMake project into distributable packages.
cpack builds the release artifacts (DEB, RPM, tarball, NSIS) from a CMake project’s install rules. The CI failures are missing install() rules (so the package is empty) and missing native packaging tools for the chosen generator.
What it does
cpack reads a CMake project’s install() rules and component definitions and produces installer packages in one or more formats via generators (TGZ, ZIP, DEB, RPM, NSIS, productbuild). It is invoked after a build/install configuration step.
Common usage
cpack -G DEB --config build/CPackConfig.cmake
cpack -G "TGZ;RPM" -B build/out
cd build && cpack -G DEB
cpack --config build/CPackConfig.cmake -V # verbose
cmake --build build --target package # equivalentOptions
| Flag | What it does |
|---|---|
| -G <gen> | Generator(s): DEB, RPM, TGZ, ZIP, NSIS |
| --config <file> | Use a specific CPackConfig.cmake |
| -B <dir> | Output directory for packages |
| -V / --verbose | Verbose diagnostics |
| -D VAR=value | Override a CPack variable |
Common errors in CI
"CPack Error: Problem creating tar ... no install rules" or an empty package means the project lacks install() rules - cpack only packages what install() stages. "CPack Error: Cannot find a generator" / DEB needs dpkg, RPM needs rpmbuild - install the native tooling for the chosen -G. Run cpack from (or point --config at) the build directory; running it elsewhere can’t find CPackConfig.cmake. Set CPACK_PACKAGE_VERSION or distros reject the package.