How to create different types of packages with CPack?

I like the way CPack works. If I want to create Debian and NSIS packages, I just tell it which components to include.

What I didn’t yet manage to figure out is whether I could create multiple different kinds of packages from the same source project. For example:

  • A NSIS package that installs the software.
  • A zip with generated documentation.
  • A wheel (which is basically a zip file) that can be used for pip install.

I would then use

cpack -G NSIS --something installer
cpack -G ZIP --something documentation
cpack -G ZIP --something pip

Not really. Different generators tend to have different install layouts (certainly wheels at least; not that it’s supported anyways) and install scripts don’t really know what generator is being used. The “best” answer is to generate all possible install rules for all supported packages use different components to select which install rules apply for which generator.

A pattern that I have used is to have a separate project that handles CPack, one per generator. These projects basically rummage through a given install prefix making its own install() calls to the right location for the given CPack generator. But this loses a lot of context (e.g., I drop basically anything that isn’t executable such as headers, CMake packages, data, etc.) as tracing these are hard and they’re not necessary for our use anyways.