Update gitversion

This commit is contained in:
Sebastian Messmer 2016-02-11 23:53:23 +01:00
parent 3be0b11029
commit 7734566bbd
22 changed files with 32 additions and 15 deletions

View File

@ -1,5 +1,3 @@
include (../vendor/gitversion/gitversion-1.8/cmake.cmake)
# Fix debfiles permissions. Unfortunately, git doesn't store file permissions.
# When installing the .deb package and these files have the wrong permissions, the package manager complains.
execute_process(COMMAND /bin/bash -c "chmod 0755 ${CMAKE_CURRENT_SOURCE_DIR}/debfiles/*")

View File

@ -1 +1 @@
include(gitversion-1.8/cmake.cmake)
include(gitversion-1.9/cmake.cmake)

View File

@ -1,14 +1,6 @@
set(DIR_OF_GITVERSION_TOOL "${CMAKE_CURRENT_LIST_DIR}" CACHE INTERNAL "DIR_OF_GITVERSION_TOOL")
#################################################
# Add git version information
# Uses:
# TARGET_GIT_VERSION_INIT(buildtarget)
# Then, you can write in your source file:
# #include <gitversion/version.h>
# cout << gitversion::VERSION.toString() << endl;
#################################################
function(TARGET_GIT_VERSION_INIT TARGET)
function (_CREATE_GIT_VERSION_FILE)
FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/messmer_gitversion")
FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/messmer_gitversion/gitversion")
@ -18,11 +10,38 @@ function(TARGET_GIT_VERSION_INIT TARGET)
IF(NOT ${result} EQUAL 0)
MESSAGE(FATAL_ERROR "Error running messmer/git-version tool. Return code is: ${result}")
ENDIF()
TARGET_INCLUDE_DIRECTORIES(${TARGET} PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/messmer_gitversion")
endfunction (_CREATE_GIT_VERSION_FILE)
function(_SET_GITVERSION_CMAKE_VARIABLE OUTPUT_VARIABLE)
# Load version string and write it to a cmake variable so it can be accessed from cmake.
FILE(READ "${CMAKE_CURRENT_BINARY_DIR}/messmer_gitversion/gitversion/version.h" VERSION_H_FILE_CONTENT)
STRING(REGEX REPLACE ".*VERSION_STRING = \"([^\"]*)\".*" "\\1" VERSION_STRING "${VERSION_H_FILE_CONTENT}")
MESSAGE(STATUS "Version from git: ${VERSION_STRING}")
SET(GITVERSION_VERSION_STRING "${VERSION_STRING}" PARENT_SCOPE)
SET(${OUTPUT_VARIABLE} "${VERSION_STRING}" CACHE INTERNAL "${OUTPUT_VARIABLE}")
MESSAGE(STATUS "Output: ${OUTPUT_VARIABLE}: ${${OUTPUT_VARIABLE}}")
endfunction(_SET_GITVERSION_CMAKE_VARIABLE)
######################################################
# Add git version information
# Uses:
# TARGET_GIT_VERSION_INIT(buildtarget)
# Then, you can write in your source file:
# #include <gitversion/version.h>
# cout << gitversion::VERSION.toString() << endl;
######################################################
function(TARGET_GIT_VERSION_INIT TARGET)
_CREATE_GIT_VERSION_FILE()
TARGET_INCLUDE_DIRECTORIES(${TARGET} PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/messmer_gitversion")
_SET_GITVERSION_CMAKE_VARIABLE(GITVERSION_VERSION_STRING)
endfunction(TARGET_GIT_VERSION_INIT)
######################################################
# Load git version information into a cmake variable
# Uses:
# GET_GIT_VERSION(OUTPUT_VARIABLE)
# MESSAGE(STATUS "The version is ${OUTPUT_VARIABLE}")
######################################################
function(GET_GIT_VERSION OUTPUT_VARIABLE)
_CREATE_GIT_VERSION_FILE()
_SET_GITVERSION_CMAKE_VARIABLE(${OUTPUT_VARIABLE})
endfunction(GET_GIT_VERSION OUTPUT_VARIABLE)