I would like to exclude nearly all the files installed by external projects (that are otherwise needed as dependencies) when installing a project and when creating the packages, but I cannot quite figure out how to do that properly.
I’m trying to use CPack on a project with tons of external dependencies which are fetched via FetchContent and built from source. But most of those dependencies are just build-time dependencies and I don’t want to end up with them being installed alongside our own targets.
For example: the sources need Google Test for running the internal tests, but I don’t want to install GTest when the project gets installed. The project needs Boost. It can also simply take Boost from the system, but in case it fetches the sources during the configure stage, it just compiles static libraries and the headers are not needed by the end user, they are just private dependencies required during the build of the project.
Basically: except for a small percentage of external dependencies that I want to get installed, I don’t want anything else than what’s defined inside the project.
Maybe I just don’t know how to prevent the installation of external targets (I would be grateful if someone can point it out how to do that). The only useful way I found was to define COMPONENT
for each internal installation target and install just the components I need. It is still annoying because cmake --install .
doesn’t work out of the box, but it’s somewhat acceptable.
Now I tried to build packages with CPack.
With
set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP)
set(CPACK_DEB_COMPONENT_INSTALL YES)
and a carefully crafted set of cpack_add_install_type
, cpack_add_component_group
, cpack_add_component
, … I can get precisely the Debian packages that I want, except that I don’t find a way to get rid of myproject-unspecified_0.1.1_amd64.deb
that bundles all the unwanted targets into something I didn’t ask for. Somewhat annoying, but I can easily just throw that file away, that’s not a big deal.
I also tried using
get_cmake_property(CPACK_COMPONENTS_ALL COMPONENTS)
list(REMOVE_ITEM CPACK_COMPONENTS_ALL "Unspecified")
without any success.
But now I want to create a .zip
file for Windows.
If I set
set(CPACK_ARCHIVE_COMPONENT_INSTALL YES)
then I get precisely the files I need, except that they are in two separate zip files when I would in fact prefer a single one. In contrast to DEB, I don’t get any Unspecified targets which is really really good, I’m just baffled why it’s inconsistent.
Now, the weird thing is that as soon as I set that variable to NO (which is the default), all the “junk files” (installation targets from external projects) that I wanted to get rid of end up being in that single zip.
The installer generated by NSIS seems fine, but I would really like to provide a simple zip as well.
So my main question is: how do I avoid all the “Unspecified” components from ending up in the ZIP file for Windows as generated by CPack?
Subquestion: what’s the proper way to set a different CPACK_PACKAGING_INSTALL_PREFIX
for Debian packages (for example /opt/myproject
) and for Windows zips (ideally empty)?