I have a file called version.cmake that my root CMakeLists.txt
includes. There is only a single line in this file:

set( BUILD_VERSION 1.2.3.4 CACHE STRING "Version of the product" )

I have two scenarios where this version number setting needs to work
slightly differently from a CMake perspective:

1. Our CI build server does a fresh clone of our repo, and generates
from scratch. It sometimes needs to override the version number from
the command line via arguments. So it will do:

-D BUILD_VERSION=99.99.1.2

This works since it's a cache variable. In fact, the current solution
ONLY works well for this scenario (since it will allow overriding from
command line, but also allow the file to set the value if it is not
specified as a -D argument).

2. Local work machine builds. Local builds never override using -D,
they always use what is in the version.cmake file. However, because
it's a cache variable and I'm not using FORCE with set(), it never
updates if I change the version and push it to origin. This is the
missing requirement: it needs to update when the number (value)
changes in version control

I thought of making a BUILD_VERSION_OVERRIDE that is only accepted on
the command line, and if specified, it will set the BUILD_VERSION
value to the overridden value. However, I don't like the idea of 2
separate variables to manage this. Using a non-cache variable doesn't
allow overriding with the same variable value on the command line
either.

What's the best solution here for my situation?
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to