Feature request: Get targets list from configured buildsystem from command line, not file api

It would be very convenient to add flag like --list-targets into the cmake --build <build-dir> to get the human-readable (and possibly machine-readable in JSON/another format) list of targets.
Currently it’s very difficult to get the actual targets list, one possible way is the cmake-file(7) api (parsing the codemodel-v2 query’s ‘targets’ dictionary in JSON) which is intended to use in IDEs’ integrations.

I also think that this parameter may have the same name as the ctest’s way to print info about tests: cmake --build <build-dir> -N.

This can only be retrieved by rerunning the configure. Why is the file-api not suitable here?

Ok, we may add this flag into configure mode :blush: