Thank you for pointing me to that issue, it does sound like the same bug.
The solution from that discussion seems to be calling cpack_add_component after include(CPack), but I’m not actually calling include(CPack) anywhere – because I’m trying to generate separate installers for each subproject, I’m generating CPackConfig files for each subproject during CMake configure, and then calling cpack --config <conf> for each of these generated CPack config files.
I tried setting CPACK_COMPONENTS_ALL to just my desired install component in each of my generated CPack config files, but I still get the same error, an empty pkg.
This brings up a related question – can CPack be included multiple times in the same build tree? Perhaps I should be calling include (CPack) once for each subproject. I was under the impression that CPack could only be included once per build tree, so I needed to generate each individual CPack config myself.
I believe you can only really safely call include(CPack) once in a project. It may be possible to include more than once from separate directories which have no common parent directories, but I wouldn’t be surprised if some part of the process does things internally to break that.
You should also be aware that all install components defined throughout the whole build are added to a global CPACK_COMPONENTS_ALL property. You’d have to account for that too if you were trying to include CPack more than once.
I see. So my use case, of wanting to generate separate installers for multiple subprojects within a monorepo, is simply not well supported by CMake?
Even if I can’t include(CPack) multiple times, it seems like I should be able to manually generate a CPack config file for each sub-project’s installer. It works for the DMG generator, but not the PKG generator…