Have find_package() fall back to trying OS-distribution-specific package search
The documentation for find_package() suggests CMake will try to locate a package in one of two ways:
- Search for a Find.cmake file
- Search for a config.cmake file (or set of files)
I claim this is not good enough, and that there should be further fallback.
From the perspective of the user trying to configure a project which depends on some package - it is reasonable to expect CMake to perform "basic due dilligence" in finding the package. And that means, that if the host OS distribution has a (reasonably-well-known) package registration/location mechanism - CMake should search it when told to find_package()
. It is surprising, unintuitive, and IMNSHO unreasonable, not to do so.
On Linux, that would mean, specifically using pkg-config (or internal CMake functionality which locates and parses .pc
files); although there may be alternatives I'm not aware of. In theory, one could argue that apt/dnf/YaST could be usable here, but let's forget about that for now.
As for other OSes - I believe *BSD's, including perhaps MacOS, have something similar to pkg-config, called pkgconf, right? So that.
Notes:
- Such a change would mean that what we now achieve as
find_package(PkgConfig)
would be made one of the actions which CMake undertakes "on its own", like searching for a language compiler for project languages, searching for the standard library etc. - Of course this should be a configurable option / policy. Project authors might want to avoid this for some reason.