# CMake & CPack with multiple packages on a monorepo

**URL:** https://discourse.cmake.org/t/cmake-cpack-with-multiple-packages-on-a-monorepo/15340
**Category:** Usage
**Created:** [November 24, 2025, 11:09am UTC](https://discourse.cmake.org/t/cmake-cpack-with-multiple-packages-on-a-monorepo/15340 "2025-11-24T11:09:41Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![w124513](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/w/cab0a1/32.png) [@w124513](https://discourse.cmake.org/u/w124513)
#### Post date: [November 24, 2025, 11:09am UTC](https://discourse.cmake.org/t/cmake-cpack-with-multiple-packages-on-a-monorepo/15340/1 "2025-11-24T11:09:41Z")

</div>

Hello everyone,

we are building our packages on a monorepo which contains a set of common components and some specific components used only for specific packages.

To be more specific: assume we have three components A, B and C. There is package foo that uses A and B. Package bar requires A and C. CPack should be instructed to package only the neccessary libraries (as in: package bar contains only A and C).

Reality is even a bit more complex (C also requires D and B has a dependency on F plus external libraries; also the amount of libraries would exceed the alphabet). I hope that above abstraction provides enough information to serve as a minimal example.

Building with CMake works pretty straightforward - using a collector target and proper dependencies. Packaging is a bit more complex.

Currently all targets are flagged optional. Using that and the collector target, CPack will pick up only built targets and package them. Nevertheless, a reconfiguration is required when switching between packages.

What is the preferred / best practice to use CMake / CPack with such a layout?
