[CMake] Version embedding - how to cause a command when make is run?

Alan W. Irwin irwin at beluga.phys.uvic.ca
Thu Oct 4 13:07:25 EDT 2007


On 2007-10-04 15:34+0100 Atwood, Robert C wrote:

> [...]I've tried the following in CMakeLists, placing the output of
> 'svnversion' and similar commands into an included source file and it
> works [...]

> Can some form of dependency be set so that if any source file is
> changed [...]

> Or, should I use another way to do what I want?

One possibility is to use subversion (which presumably you are using since
you referred to svnversion) keyword functionality.

For example, if you put $Id$ into your source code comments, and then run

svn propset svn:keywords 'Author Date Id Revision' filename

After the svn commit of filename, the source code is changed so the $Id$ is expanded
into something like

$Id: plcore.c 7355 2007-02-05 02:35:12Z airwin $

How you place the $ID$ placeholder in your source will, of course, affect
whether or not it appears in the executable.

The Makefiles generated by CMake notice the source code change and rebuild
the executables accordingly.

I haven't used svnversion myself, but it looks like all it does is summarize
revision numbers in the entire repository.  The above solution actually
tells the exact revision number of each source file (along with a lot of
other information you can eliminate by using the $Revison$ placeholder
rather than $Id$).

If that is more information than you want in your executables, then to
answer your original query, I suggest looking in the cmake documentation for
the ADD_CUSTOM_COMMAND(TARGET signature.  I believe the POST_BUILD option
for that command will do exactly what you want, but it has been a while
since I tried that option.

BTW, I am glad to hear your hair-pulling is now so much reduced that
your hair is growing back again.  :-)

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list