[CMake] CMake generated build number?

Bill Hoffman bill.hoffman at kitware.com
Wed Nov 5 10:36:44 EST 2008


Blezek, Daniel J. wrote:
> Hi Mike,
> 
>   This only works during the CMake configure process, not during the
> build.  So it's possible for this information to be out of date.  I
> think I'll have to make a bogus target to grab the info from Subversion,
> which is not what I had wanted to do.
> 

You should just use a cmake -P script to create a header file or .cxx 
file that has the information you want in it.

You would use a custom command to drive this.

You should be able to follow this FAQ entry:

http://www.vtk.org/Wiki/CMake_FAQ#How_do_I_generate_an_executable.2C_then_use_the_executable_to_generate_a_file.3F

So, something like this:

  ADD_CUSTOM_COMMAND(
    OUTPUT myVersion.cxx
    COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/version.cmake
    DEPENDS generate ${CMAKE_CURRENT_SOURCE_DIR}/version.cmake
    )
  ADD_EXECUTABLE(product product.c myVersion.cxx)

version.cmake:
execute_process(svn ....)
configure_file(myVersion.cxx.in myVersion.cxx)

-Bill


More information about the CMake mailing list