# FetchContent, find\_package, and FeatureSummary

**URL:** https://discourse.cmake.org/t/fetchcontent-find-package-and-featuresummary/10867
**Category:** Code
**Created:** [May 17, 2024, 2:46pm UTC](https://discourse.cmake.org/t/fetchcontent-find-package-and-featuresummary/10867 "2024-05-17T14:46:25Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![petk](https://discourse.cmake.org/user_avatar/discourse.cmake.org/petk/32/4555_2.png) [@petk](https://discourse.cmake.org/u/petk)
#### Post date: [May 17, 2024, 2:46pm UTC](https://discourse.cmake.org/t/fetchcontent-find-package-and-featuresummary/10867/1 "2024-05-17T14:46:25Z")

</div>

Hello, are there any best practices or patterns how to properly use FetchContent, FeatureSummary and FindPackageName modules?

For example, if I want to integrate FeatureSummary with FetchContent there is additional code needed for each dependency:

```cmake
get_cmake_property(packagesNotFound PACKAGES_NOT_FOUND)
list(REMOVE_ITEM packagesNotFound <PackageName>)
set_property(GLOBAL PROPERTY PACKAGES_NOT_FOUND packagesNotFound)
get_cmake_property(packagesFound PACKAGES_FOUND)
set_property(GLOBAL APPEND PROPERTY PACKAGES_FOUND <PackageName>)

```

Then another issue I’m having is all the additional possible things that find module might set, expose, etc. When the FetchContent\_Declare calls find\_package() itself, it doesn’t execute the code from the local or upstream FindPackageName.cmake module and code needs to be duplicated for that part also manually. Is there a better way? Or should the FindPackageName.cmake module be refactored into a regular module?

And the last issue I’m noticing at the moment is the logging. The FetchContent\_Declare uses find\_package() with QUIET option. Is there any practice how to customize the logging messages when package is found, like the default find\_package() outputs, or how to disable the QUIET option when using FetchContent\_Declare?

Thank you.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [May 17, 2024, 9:56pm UTC](https://discourse.cmake.org/t/fetchcontent-find-package-and-featuresummary/10867/2 "2024-05-17T21:56:09Z")

</div>

> For example, if I want to integrate FeatureSummary with FetchContent there is additional code needed for each dependency

Integration between FetchContent and FeatureSummary has been raised in the issue tracker, but no-one is working on it that I’m aware of. [https://gitlab.kitware.com/cmake/cmake/-/issues/25322](https://gitlab.kitware.com/cmake/cmake/-/issues/25322)

> Then another issue I’m having is all the additional possible things that find module might set, expose, etc. When the FetchContent\_Declare calls find\_package() itself, it doesn’t execute the code from the local or upstream FindPackageName.cmake module and code needs to be duplicated for that part also manually. Is there a better way? Or should the FindPackageName.cmake module be refactored into a regular module?

This sounds to me like the thing you’re trying to bring in with FetchContent doesn’t meet the requirements of doing so. When a dependency is brought into the build with FetchContent, it is expected that the dependency will define the same targets, commands, etc. that it would if it had been brought in using `find_package()` from an installed package. This normally means the dependency project has to define ALIAS targets to match the namespaced names of the targets when installed.

Things get worse when you’re expecting details normally provided by a Find module rather than a package’s own `<packageName>-config.cmake` file. A Find module is maintained externally to the package it is providing. There’s nothing official about a Find module (except those provided by CMake itself). The package isn’t bound to honouring whatever the Find module author decided to make available. If you’re the author of both the package and the Find module, then get rid of the find module and provide a `<packageName>-config.cmake` instead, and include it with your package when you distribute it.

> And the last issue I’m noticing at the moment is the logging. The FetchContent\_Declare uses find\_package() with QUIET option. Is there any practice how to customize the logging messages when package is found, like the default find\_package() outputs, or how to disable the QUIET option when using FetchContent\_Declare?

There’s no facility for disabling the `QUIET` behavior when FetchContent tries calling `find_package()` at the moment.
