[CMake] Action to perform unconditionally

Michael Hertling mhertling at online.de
Wed Feb 2 08:18:00 EST 2011


On 02/02/2011 01:44 PM, Ilja Golshtein wrote:
> Hello!
> 
> I am trying to generate version.h in my project as described http://addisu.taddese.com/blog/inserting-svn-revision-number-in-your-cc-code/
> 
> I think the most natural place to do it is my project root CMakeLists.txt. 
> The problem is it does not contain any target - just setting some variables and add_subdirectory(src)
> 
> The question is what is the best way to perform an action make-time unconditionally.

You might use a custom target to trigger a CMake script which invokes
EXECUTE_PROCESS() to query Subversion for the current revision number
and CONFIGURE_FILE() to transform a version.h.in template into the
desired version.h header. Finally, use ADD_DEPENDENCIES() to establish
a dependency of your targets on the custom target. See [1] for a quite
similar example.

Regards,

Michael

[1] http://www.mail-archive.com/cmake@cmake.org/msg29944.html


More information about the CMake mailing list