[CMake] How to properly handle build version number in CMake script for project

Robert Dailey rcdailey.lists at gmail.com
Mon Apr 10 12:04:03 EDT 2017


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.

1. On build server, if it overrides it with -D, then it does not set
it by hand. If it doesn't override, it will use the fixed version in
the file
2. On work machines, it's never defined prior, so it sets it with the
fixed version.

On Mon, Apr 10, 2017 at 9:15 AM, Bruce Stephens
<bruce.r.stephens at gmail.com> wrote:
> On Mon, Apr 10, 2017 at 2:36 PM, Bruce Stephens
> <bruce.r.stephens at gmail.com> wrote:
>> You could do something like
>>
>> if(NOT "${BUILD_VERSION}")
>>   set(BUILD_VERSION 1.2.3.4)
>> endif()
>
>
> That doesn't work at all, come to think of it. I suspect your best bet
> is to handle
> the caching yourself (likely using a file in ${CMAKE_BINARY_DIR} and
> maybe "include(... OPTIONAL)"). That should allow whatever behaviour
> you want.
>
> I note that llvm's builds have the same sort of problem, so whatever
> fix is required
> isn't obvious even to obviously bright people. (That is, when the
> version switched
> from 4.0.0 to 5.0.0 my builds didn't change their version number. I
> had to remove the
> build directory and build again from clean.)


More information about the CMake mailing list