# is there a way to collect packages list?

**URL:** https://discourse.cmake.org/t/is-there-a-way-to-collect-packages-list/5053
**Category:** Development
**Tags:** os:linux
**Created:** [February 18, 2022, 8:58am UTC](https://discourse.cmake.org/t/is-there-a-way-to-collect-packages-list/5053 "2022-02-18T08:58:57Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![shouhuanxiaoji](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/f4b2a3/32.png) [@shouhuanxiaoji](https://discourse.cmake.org/u/shouhuanxiaoji)
#### Post date: [February 18, 2022, 8:58am UTC](https://discourse.cmake.org/t/is-there-a-way-to-collect-packages-list/5053/1 "2022-02-18T08:58:57Z")

</div>

HI, everyone  
I am writing a tool related to cmake, it will collect all of packages declared in cmakelists.txt by every command find\_package.  
so given a cmake-related project, this tool will output a json object, then thought apt or rpm, it will try resolving the dependency problem. like bellow:

```auto
{
  "sdl": {
    "installed": "no",
    "model": "",
    "version": "2.0"
  },
  "jpeg": {
    "installed": "yes",
    "model": "REQUIRED",
    "version": ""
  },
  ...
}

```

I have found a private method named cmake::findpackage in cmake\_source\_top\_dir\_/Source/cmake.h, I guess it meens that, give it a vector\<std::string\>, it will try finding needed package.  
but how to collect a packages list in cmakelists.txt and cmakelists.txt in subdirectories?

I can just collect them by parsing the command find\_package(), but if there is a “if” outside the command, it will be complex.  
thanks.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 18, 2022, 12:58pm UTC](https://discourse.cmake.org/t/is-there-a-way-to-collect-packages-list/5053/2 "2022-02-18T12:58:58Z")

</div>

What is the use case here?

But, in the line I think you’re looking at, if you’re looking to collect `find_package` calls, there’s no real way to do this right now. Knowing _why_ a package is being found is missing from CMake’s knowledge. The closest I’ve seen (written) is [VTK’s `vtk_module_find_package`](https://gitlab.kitware.com/vtk/vtk/-/blob/4e2ee1aa0ea981e2b230c2826dcbc170a6f3f7f0/CMake/vtkModule.cmake#L4347) that is used instead of `find_package` that collects information about the request and the result so that it can later be generated into the `config.cmake` pipeline. This is not trivial code.

---

<div class="post-metadata">

### Author: ![neundorf](https://discourse.cmake.org/user_avatar/discourse.cmake.org/neundorf/32/2075_2.png) [@neundorf](https://discourse.cmake.org/u/neundorf)
#### Post date: [February 18, 2022, 9:54pm UTC](https://discourse.cmake.org/t/is-there-a-way-to-collect-packages-list/5053/3 "2022-02-18T21:54:02Z")

</div>

Maybe this helps ?

[https://cmake.org/cmake/help/latest/module/FeatureSummary.html](https://cmake.org/cmake/help/latest/module/FeatureSummary.html)

You can also have a look at its implementation.

Alex

---

<div class="post-metadata">

### Author: ![shouhuanxiaoji](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/f4b2a3/32.png) [@shouhuanxiaoji](https://discourse.cmake.org/u/shouhuanxiaoji)
#### Post date: [February 21, 2022, 3:38am UTC](https://discourse.cmake.org/t/is-there-a-way-to-collect-packages-list/5053/4 "2022-02-21T03:38:36Z")

</div>

thanks!
