2011/7/12 Thomas Petazzoni <thomas.petazz...@free-electrons.com>: > Hello, > > Le Sun, 05 Jun 2011 11:02:00 +0200, > Quintus <sutn...@gmx.net> a écrit : > >> I'm working on a git-versioned project that I'd like to display it's >> version number for development versions like this: >> >> 1.2.3-dev (commit abc1234 on devel, 12/4/10) > > For similar need I did something like : > > execute_process(COMMAND sh ../getlocalversion OUTPUT_VARIABLE MYPROG_VERSION) > add_definitions(-DMYPROG_VERSION="${MYPROG_VERSION}") > > where getlocalversion is a shell script that does : > > printf "%s%s" $(git rev-parse --verify --short HEAD) $(if test `git > diff-index --name-only HEAD | wc -l` -ne 0 ; then echo "-dirty"; fi) > > However, I am not very happy with this, because the version is > determined at configuration time, and not at compile time. Therefore, > if I make some changes and commit them to the Git repository without > re-doing the CMake configuration step, the program version isn't > changed. Any idea on how to make sure that the version of the program > is updated at every compilation ?
If you want to execute **build time** scripts you should use add_custom_command/add_custom_target You'll have to make your script create a header that will be included in the concerned source file(s), something like: add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.h COMMAND getlocalversion --output ${CMAKE_CURRENT_BINARY_DIR}/version.h) If the script is smart enough not to re-create the file if the version did not change then it should work without too much overhead. If not this will trigger a undue recompilation. if the version.h concerns a single target you could use: add_custom_command(TARGET versionedTarget PRE_BUILD COMMAND getlocalversion --output ${CMAKE_CURRENT_BINARY_DIR}/version.h) this build of the "versionedTarget" should trigger the command. -- Erk Membre de l'April - « promouvoir et défendre le logiciel libre » - http://www.april.org _______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake