[CMake] How to properly handle build version number in CMake script for project
Robert Dailey
rcdailey.lists at gmail.com
Mon Apr 10 14:32:32 EDT 2017
Actually this seems to work:
if( BUILD_VERSION )
set( version_override ${BUILD_VERSION} )
unset( BUILD_VERSION CACHE )
set( BUILD_VERSION ${version_override} )
unset( version_override )
else()
set( BUILD_VERSION 7.1.1.2 )
endif()
It's a bit messy but gets the job done, and doesn't require
configure_file(). Maybe there is a way to clean this up even more?
I noticed that unset( BUILD_VERSION CACHE ) actually unsets non-cache
versions of a variable too, so I had to use the temporary variable to
transfer the value.
On Mon, Apr 10, 2017 at 1:15 PM, Robert Dailey <rcdailey.lists at gmail.com> wrote:
> Sorry you're right, this isn't working because -D creates a cache
> entry for the variable, which breaks it.
>
> So maybe more ideas on the configure_file() solution would be ideal...
> unsetting the cache variable might work as well, I have to toy around
> with this.
>
> On Mon, Apr 10, 2017 at 12:48 PM, Bruce Stephens
> <bruce.r.stephens at gmail.com> wrote:
>> On Mon, Apr 10, 2017 at 5:04 PM, Robert Dailey <rcdailey.lists at gmail.com> wrote:
>>> Actually I think your idea does work. Why do you think it won't? I'm
>>> using it right now and so far it seems OK.
>>
>> I assumed (without testing, admittedly) is that it would fail if
>> someone used -D to set the value,
>> then changed some CMakeLists.txt file, then executed the build command
>> again. I'd expect that
>> to rerun cmake to update the build files and I'd fear that you'd then
>> get BUILD_VERSION from
>> the CMakeLists.txt file rather than the value explicitly set.
>>
>> However, I haven't tried it, and maybe it works fine (with the
>> generators you care about) even without
>> caching?
More information about the CMake
mailing list