How to get version from header in Find Module?

When writing a new Find Module, what is the recommended way to extract the library version from a C header file?

As an example, this FindGLPK module uses regexes to do it. This seems messy and fragile to me, and I am wondering is there are any built-in tools in CMake that make this easier.

There’s no standardised way mostly because there’s no standardised way of expressing the version within the header file. Typically though, the regex way is pretty solid because the way the version is expressed within one library does not change, quite often being also a part of an interface.

BTW: Convincing library maintainers to provide a config is always preferred to writing find modules (if that’s an option OFC)