[CMake] Pull in project version number from file
Alexander Neundorf
a.neundorf-work at gmx.net
Thu Jun 6 15:35:46 EDT 2013
On Thursday 06 June 2013, Richard Shaw wrote:
> I'm working on converting a small project from autotools to cmake and one
> of the final nit-pick issues is that the version of the software is defined
> in a file, version.h as #defines.
>
> I haven't been able to find the magic incantation of file(READ...,
> string(REGEX MATCH... to parse the version numbers. I did request that the
> version be managed within the cmake config but that was not accepted.
>
> The meaningful entries in version.h are:
>
> #define FREEDV_VERISON_MAJOR "0"
> #define FREEDV_VERSION_MINOR "96"
> #define FREEDV_VERSION_PATCH "3"
> #define FREEDV_VERSION_SUFFIX "Beta"
better do it the other way round.
Define the version number in your CMakeLists.txt:
set(FREEDV_VERISON_MAJOR "0" )
set(FREEDV_VERSION_MINOR "96" )
set(FREEDV_VERSION_PATCH "3" )
and then create the version header from that using configure_file:
configure_file(version.h.in version.h)
with version.h.in being something like
#define FREEDV_VERISON_MAJOR "${FREEDV_VERISON_MAJOR}"
#define FREEDV_VERSION_MINOR "${FREEDV_VERSION_MINOR}"
#define FREEDV_VERSION_PATCH "${FREEDV_VERSION_PATCH}"
This way you have the version numerb in your header, and also in your cmake
files.
Alex
More information about the CMake
mailing list