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

Bruce Stephens bruce.r.stephens at gmail.com
Mon Apr 10 10:15:27 EDT 2017


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