I'd like to keep very close track of what version of my code I'm using for documentation purposes. Therefore I'd like to display the version of code I have compiled every time I run my program..
I've been using this previous question as reference.
How can I pass git SHA1 to compiler as definition using cmake?
I am using the two files that Ryan Pavlik suggested from his github repo, seen below: https://github.com/rpavlik/cmake-modules/blob/master/GetGitRevisionDescription.cmake.in#L13 https://github.com/rpavlik/cmake-modules/blob/master/GetGitRevisionDescription.cmake
And I have the following:
CMakeLists.txt
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/")
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GITHASH)
set(test_GITHASH "\"${GITHASH}\"")
include_directories("${PROJECT_BINARY_DIR}")
configure_file ("${PROJECT_SOURCE_DIR}/testgithash.h.in"
"${PROJECT_BINARY_DIR}/testgithash.h" )
testgithash.h.in
#define test_GITHASH @test_GITHASH@
So far I have my final executable displaying the hash from my testgithash.h file that is generated, but that header file is only refreshed when I run cmake. So really my question is, does anyone know of way that I can force cmake to re-run when I run make if my hash has changed? Or is there a way I can put the git hash functionality I'm looking for directly into my generated makefile rather than in my CMakeLists.txt?
Thanks in advance for any help!