It’s in part to do with parts of the example that you’ve left out.
If you have a call to find_dependency() nestled in among those lines (which the original example in the book does) and the dependency package you try to find has been implemented with the same pattern, its comps variable would overwrite the one for this package. When you then try to iterate over comps in your package’s foreach() loop instead of ${CMAKE_FIND_PACKAGE_NAME}_comps, you would be iterating over a list of components for the dependency, not for this package.
You don’t have to do the check that way if you don’t want to. It just happens to be a convenient way to do it when you know there will be at least one exported target. In the case of a header-only library, there’s no library that needs to be installed for runtimes to use, so you can just skip over checking that particular component.
Craig is also drowning in his backlog of stuff to get done by the end of the year. ![]()