Reading c-style preprocessor macros

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Reading c-style preprocessor macros

Daniel Stonier
I've been digging through the documentation, but I cannot seem to find anything which can read the value of a c style defined macro into a cmake variable.

There's CheckSymbolExists, but that just flags the resulting cmake variable as true or false. It doesn't actually read the definition into the variable. 

I also checked FindBoost to see how they grab boost's version number - seems the do a file read and a regex on the resulting value. 

Is there an easy way to do this? I would have thought it would have been fairly common functionality - for instance, to gather information about posix options.

Regards,
Daniel.

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Reading c-style preprocessor macros

Alexander Neundorf-3
On Sunday 13 December 2009, Daniel Stonier wrote:

> I've been digging through the documentation, but I cannot seem to find
> anything which can read the value of a c style defined macro into a cmake
> variable.
>
> There's CheckSymbolExists, but that just flags the resulting cmake variable
> as true or false. It doesn't actually read the definition into the
> variable.
>
> I also checked FindBoost to see how they grab boost's version number -
> seems the do a file read and a regex on the resulting value.
>
> Is there an easy way to do this? I would have thought it would have been
> fairly common functionality - for instance, to gather information about
> posix options.

Either read and regex the headers, or build a small executable which will
contain a string with the value you are interested in. Then you can use
file(STRINGS) to read this value.
This is done by cmake e.g. to determine the compiler, the size of types
(CheckTypeSize.cmake) and I think in some other places too.

If possible, you should try to avoid try_run() since this brings problems in
case the package should be cross compiled some day by somebody.


Alex
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake