# Libraries using FetchContent

**URL:** <https://discourse.bemanproject.org/t/libraries-using-fetchcontent/570>\
**Category:** Beman Libraries\
**Tags:** cmake\
**Created:** [April 1, 2026, 6:31pm UTC](https://discourse.bemanproject.org/t/libraries-using-fetchcontent/570 "2026-04-01T18:31:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pdimov](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.bemanproject.org/pdimov/32/149_2.png) [@pdimov](https://discourse.bemanproject.org/u/pdimov)\
**Post date:** [April 1, 2026, 6:31pm UTC](https://discourse.bemanproject.org/t/libraries-using-fetchcontent/570/1 "2026-04-01T18:31:47Z")

</div>

Currently, libraries such as beman::task and beman::net use FetchContent in their CMakeLists.txt files to automatically download their dependencies (beman::execution in the first case, beman::execution and beman::task in the second), even when the library is a subproject itself.

I don’t think this is a good practice. I’ve empirically found that it’s most ergonomic when subprojects don’t try to do anything “clever” about their dependencies, leaving it to the root project to guarantee their acquisition. That is, including beman::net should just link to beman::task and beman::execution, without doing anything else. The top level project would then be responsible for issuing the appropriate FetchContent calls for each library.

(Neither should the CMakeLists.txt files issue `find_package`. `find_package` should also be issued by the root project, and the config file for the library would then call `find_dependency` as appropriate. CMakeLists.txt files should not.)

---

<div class="post-metadata">

**Author:** ![ednolan](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.bemanproject.org/ednolan/32/131_2.png) [@ednolan](https://discourse.bemanproject.org/u/ednolan)\
**Post date:** [April 1, 2026, 7:13pm UTC](https://discourse.bemanproject.org/t/libraries-using-fetchcontent/570/2 "2026-04-01T19:13:42Z")

</div>

I agree. `beman.exemplar`, which is intended to be the model for all beman libraries, will only use FetchContent if the user passes in `-DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=./infra/cmake/use-fetch-content.cmake` (or if the root project does something like you’re describing). The issues with `beman.task`, `beman.execution`, and `beman.net` are a result of drift from `beman.exemplar`, which I will be working toward bringing into alignment.

---

<div class="post-metadata">

**Author:** ![ClausKlein](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.bemanproject.org/clausklein/32/136_2.png) [@ClausKlein](https://discourse.bemanproject.org/u/ClausKlein)\
**Post date:** [April 3, 2026, 10:08am UTC](https://discourse.bemanproject.org/t/libraries-using-fetchcontent/570/3 "2026-04-03T10:08:54Z")

</div>

Fetch content is only used if find\_package fails!

And find\_package is needed in each case!

---

<div class="post-metadata">

**Author:** ![pdimov](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.bemanproject.org/pdimov/32/149_2.png) [@pdimov](https://discourse.bemanproject.org/u/pdimov)\
**Post date:** [April 3, 2026, 11:01am UTC](https://discourse.bemanproject.org/t/libraries-using-fetchcontent/570/4 "2026-04-03T11:01:38Z")

</div>

No, as I said, libraries shouldn’t be calling `find_package` either in their CMakeLists.txt files when they aren’t the root project.

The root project should call `find_package`, which will find the installed config file; this config file (and not CMakeLists.txt) would then call `find_dependency` for the library dependencies.

---

<div class="post-metadata">

**Author:** ![ClausKlein](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.bemanproject.org/clausklein/32/136_2.png) [@ClausKlein](https://discourse.bemanproject.org/u/ClausKlein)\
**Post date:** [April 3, 2026, 11:07am UTC](https://discourse.bemanproject.org/t/libraries-using-fetchcontent/570/5 "2026-04-03T11:07:31Z")

</div>

In each case the top level project can do this call to find\_package, than each following call use the cached result.

---

<div class="post-metadata">

**Author:** ![ednolan](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.bemanproject.org/ednolan/32/131_2.png) [@ednolan](https://discourse.bemanproject.org/u/ednolan)\
**Post date:** [April 3, 2026, 12:01pm UTC](https://discourse.bemanproject.org/t/libraries-using-fetchcontent/570/6 "2026-04-03T12:01:13Z")

</div>

> Fetch content is only used if find\_package fails!

This isn’t the pattern we want. If find\_package fails, and the user doesn’t want to use FetchContent, then using FetchContent as a fallback anyway is a bad default for them; they should just get an error. Users who want FetchContent should have to communicate that explicitly.

---

<div class="post-metadata">

**Author:** ![ClausKlein](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.bemanproject.org/clausklein/32/136_2.png) [@ClausKlein](https://discourse.bemanproject.org/u/ClausKlein)\
**Post date:** [April 3, 2026, 2:56pm UTC](https://discourse.bemanproject.org/t/libraries-using-fetchcontent/570/7 "2026-04-03T14:56:55Z")

</div>

The dependencies provider is a BUG, all find parameters are ignored, EXCLUDE\_FROM\_ALL is set, …
