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

2017-04-10 Thread Robert Dailey
OK weirdly, tested again, this also works and is a little more simplified (although more confusing, since now we're intermixing non-cache and cache variables with the same name; behavior is not exactly clear, or well-defined. if( BUILD_VERSION ) set( BUILD_VERSION ${BUILD_VERSION} )

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

2017-04-10 Thread Robert Dailey
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,

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

2017-04-10 Thread Robert Dailey
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,

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

2017-04-10 Thread Bruce Stephens
On Mon, Apr 10, 2017 at 5:04 PM, Robert Dailey 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,

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

2017-04-10 Thread Hendrik Sattler
Hi, You could make it a non-cache variable and manage the caching yourself. The cache is your version.cmake. Before including it, check if the variable is set and update your version cmake file, possibly with configure_file(). After that, unset() the cache variable and include your cmake

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

2017-04-10 Thread Robert Dailey
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

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

2017-04-10 Thread Bruce Stephens
On Mon, Apr 10, 2017 at 2:36 PM, Bruce Stephens 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

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

2017-04-10 Thread Bruce Stephens
You could do something like if(NOT "${BUILD_VERSION}") set(BUILD_VERSION 1.2.3.4) endif() On Mon, Apr 10, 2017 at 2:29 PM, Robert Dailey wrote: > I have a file called version.cmake that my root CMakeLists.txt > includes. There is only a single line in this file: > >