[CMake] Interrogate header files without TRY_RUN

David Gobbi david.gobbi at gmail.com
Thu Jun 16 13:27:07 EDT 2011


On Thu, Jun 16, 2011 at 10:58 AM, Alexander Neundorf
<a.neundorf-work at gmx.net> wrote:

> You could simply read the header file and try to grep fpor the version
> numbers. Works quite good in many cases.
>
> Or you could try to mess around with try_compile(), and search in the produced
> binary for the version strings. This may need some clever tricks to actually
> create such a string in the executable.
> CMake does that for a few things, e.g. to determine the sizes of types,
> compiler ID, and I think more, see e.g. Modules/CheckTypeSize.*.

Grepping the headers wouldn't be as reliable as I would like...
usually version numbers are stored in an internal config header file
that might be moved or renamed from version to the next.  Searching
the binaries... that would really be a last resort.

Does CMake provide a cross-platform way of running the preprocessor
and dumping all macros?  For example with gcc, I can do "gcc -E -dD"
but I would have to do the same for all other compilers.

 - David


More information about the CMake mailing list