is there a way to collect packages list?

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:

{
  "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.

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 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.

Maybe this helps ?

https://cmake.org/cmake/help/latest/module/FeatureSummary.html

You can also have a look at its implementation.

Alex

thanks!