problem:
when adding a new library (with FetchContent_Declare & MakeAvailable) I have no idea what targets are available. I can google / stackoverflow and hope someone has documented, but it’s not a good experience. I can also spelunk in the lib-config.cmake file. Or I can guess and hope the targets are sensibly named. cmake docs recommend “Check the documentation for the package or Find module to see what imported targets it defines, if any.” which doesn’t seem good enough to me!
solution:
there should be a way to list the (namespaced) targets added by a FetchContent_Declare & MakeAvailable.
(bad) workarounds:
- use a recursive subdirectory function, and print all BUILDSYSTEM_TARGETS. problems: this only prints e.g. boost_algorithm, etc not Boost::Algorithm (namespaced targets are the preferred way to include “If the dependency provides namespaced targets of the form SomePrefix::ThingName, the project should link to those rather than to any non-namespaced targets.”)
graph=$(mktemp)
cmake --graphviz=$graph builddir
rg --only-matching --no-line-number "\w*::\w*" $graph | sort -u
this will print out all namespaced targets, but it is clearly not a good solution. however it does indicate that cmake internally has this information, but just doesn’t expose it neatly.