[CMake] Making a variable a dependency...

Nicolas Desprès nicolas.despres at gmail.com
Tue Feb 7 04:53:29 EST 2012


On Sat, Feb 4, 2012 at 11:35 PM, Oliver Smith <osmith at playnet.com> wrote:
> My CMakeLists uses the Subversion repository information in a couple of
> places (it configures a file revision.h and it uses it for the CPack package
> name).
>
> The problem is that this variable is cached and retained until the cache is
> rebuilt, instead of being calculated or evaluated per make. So if I do a
> build, then do an svn update and pull some changes, it will build a new
> executable but it will stamp it with the revision number from when CMake
> last regenerated the make files...
>
> Is there a way to mark a variable as volatile or something so that CMake
> will always recalculate it and check if it has changed?
>

I had the same problem and I decided it does not worth to tackle it
perfectly. Actually, you only need the right "revision.h" at release
time. So in my project I had a 'release' target with this behavior:
1/ tag the repository
2/ make rebuild_cache
3/ make all
4/ make package
Also, this could be simplify since I think it is safer to make a
release from a clean build directory so you can just skip the first
two step and just tell your release script to checkout the right
revision before to do a cmake, make, make package.

During development phase if you really want to have the proper
"revision.h", I would suggest to add a 'force-revision' target which
recompute the revision number and regenerate the "revision.h" header.

I know I did not really answer your question but this solution is good
enough and does not require any tricks. Also I don't think it worth
running cmake each time make is called.

Regards,

-- 
Nicolas Desprès


More information about the CMake mailing list