[CMake] Automatic building app version if any one of the dependency is changed.

Matthew Woehlke matthew.woehlke at kitware.com
Wed Oct 24 16:54:53 EDT 2012


On 2012-10-17 15:24, Vivek Goel wrote:
> Using CMake I am generating a common version file.
> version.h which contains current svn version of source code.
> In all application main.c I am including this file.
> Now every application is depending on this version.h
> and everything got rebuild.
>
> I want to change this logic so application will have their own version and
> version.h file should be generated only if any other dependency of
> application is changed.

If you were using git, you could use something like 'git log -1 <list of 
files that affect the build of MyFooApp>', and put that in version.h for 
MyFooApp (and similar for other applications). I imagine you can do 
something similar with svn.

The trick is getting the list of files that affect the build of MyFooApp 
(depending on how pedantic a definition of "affects the build" you need).

If you don't mind creating version.h being a bit expensive, you could 
write a CMake script to collect the names of all files in your source 
tree that do not belong to other applications. If you don't care about 
e.g. top-level build configuration, libraries in your project, etc. 
(i.e. only files in src/apps/foo), then it's a little easier.

-- 
Matthew



More information about the CMake mailing list