[CMake] Embedding up-to-date version info in built library

Brad King brad.king at kitware.com
Mon Dec 14 15:34:03 EST 2009


Waschk,Kolja wrote:
> Hi Brad,
> 
>> You need the custom command to run every time the build starts:
> ...
>> copy-if-different check.  The key is then to make the library depend
>> on this rule at a *target* level, but only on version.h at a *file*
>> level.
> 
> Because such a custom target is "always considered out of date", the
> library that depends on it is also considered out of date and would
> be rebuilt,

That's why the key is to avoid the *file* level dependency.  The *target*
level dependency only determines the order in which the build system
evaluates targets.  Within each target the file-level dependencies are
separately evaluated.

This code:

  add_custom_target(update_version COMMAND echo updating)
  add_library(mylib version.c)
  add_dependencies(mylib update_version)

causes "updating" to print every time you type "make", but it will
build mylib only when sources change.  It works in the VS IDE too.

-Brad


More information about the CMake mailing list