use 'git describe' to generate version info for the about box and servatrice. fixes issue #20

This commit is contained in:
Max-Wilhelm Bruker 2012-02-21 01:08:16 +01:00
parent a1bcd9854f
commit 89bb8e72ee
10 changed files with 49 additions and 12 deletions

View file

@ -45,3 +45,10 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
add_subdirectory(pb)
add_library(cockatrice_common ${common_SOURCES} ${common_HEADERS_MOC})
target_link_libraries(cockatrice_common cockatrice_protocol)
add_custom_target(versionheader ALL DEPENDS version_header)
add_custom_command(
OUTPUT version_header ${CMAKE_CURRENT_BINARY_DIR}/versionheader.h
COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/getversion.cmake
)

29
common/getversion.cmake Normal file
View file

@ -0,0 +1,29 @@
find_package(Git)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --long --always
RESULT_VARIABLE res_var
OUTPUT_VARIABLE GIT_COM_ID
)
if( NOT ${res_var} EQUAL 0 )
set( GIT_COMMIT_ID "git commit id unknown")
message( WARNING "Git failed (not a repo, or no tags). Build will not contain git revision info." )
endif()
string( REPLACE "\n" "" GIT_COMMIT_ID "${GIT_COM_ID}" )
else()
set( GIT_COMMIT_ID "unknown (git not found!)")
message( WARNING "Git not found. Build will not contain git revision info." )
endif()
set( hstring "extern const char *VERSION_STRING\;\n" )
set( cppstring "const char * VERSION_STRING = \"${GIT_COMMIT_ID}\"\;\n")
file(WRITE version_string.cpp.txt ${cppstring} )
file(WRITE version_string.h.txt ${hstring} )
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_if_different version_string.h.txt ${CMAKE_CURRENT_BINARY_DIR}/version_string.h
)
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_if_different version_string.cpp.txt ${CMAKE_CURRENT_BINARY_DIR}/version_string.cpp
)