[CMake] how to get the version of a library

Tyler Roscoe tyler at cryptio.net
Mon Apr 27 22:56:23 EDT 2009


On Tue, Apr 28, 2009 at 10:12:17AM +0800, brice rebsamen wrote:
> >>>How to know the version of an installed library? My code has #if 
> >>>macros to handle different APIs. So I would need to get the version 
> >>>and set 2 variables (MAJOR and MINOR) and pass them to the compiler 
> >>>(-D).
> >>>
> >>>To be more precise, I am interested in Player/Stage. One way to get 
> >>>the version is to run the player executable. Under linux:
> >>>
> >>>VERSION=`player 2>&1 | grep "Player v" | cut -d' ' -f2`
> >>>this gives "v2.2.0". Then
> >>>MAJOR=`echo $VERSION | cut -d'.' -f2`
> >>>MINOR=`echo $VERSION | cut -d'.' -f3`

Use add_custom_command + add_custom_target to run the script (write it
in a multi-platform scripting language a la Python if you want
cross-platform functionality). Probably the easiest way to get that info
back into CMake is to write the output to a configure file and then read
that in your CMakeLists.

tyler


More information about the CMake mailing list