libcryfs/vendor/gitversion/gitversion-1.9/cmake.cmake

47 lines
2.2 KiB
CMake
Raw Normal View History

2016-02-11 16:39:42 +01:00
set(DIR_OF_GITVERSION_TOOL "${CMAKE_CURRENT_LIST_DIR}" CACHE INTERNAL "DIR_OF_GITVERSION_TOOL")
2016-02-11 23:53:23 +01:00
function (_CREATE_GIT_VERSION_FILE)
2016-02-11 16:39:42 +01:00
FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/messmer_gitversion")
FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/messmer_gitversion/gitversion")
SET(ENV{PYTHONPATH} "${DIR_OF_GITVERSION_TOOL}/src")
EXECUTE_PROCESS(COMMAND /usr/bin/env python -m gitversionbuilder --lang cpp --dir "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/messmer_gitversion/gitversion/version.h"
RESULT_VARIABLE result)
IF(NOT ${result} EQUAL 0)
MESSAGE(FATAL_ERROR "Error running messmer/git-version tool. Return code is: ${result}")
ENDIF()
2016-02-11 23:53:23 +01:00
endfunction (_CREATE_GIT_VERSION_FILE)
2016-02-11 16:39:42 +01:00
2016-02-11 23:53:23 +01:00
function(_SET_GITVERSION_CMAKE_VARIABLE OUTPUT_VARIABLE)
2016-02-11 16:39:42 +01:00
# 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}")
2016-02-11 23:53:23 +01:00
SET(${OUTPUT_VARIABLE} "${VERSION_STRING}" CACHE INTERNAL "${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)
2016-02-11 16:39:42 +01:00
endfunction(TARGET_GIT_VERSION_INIT)
2016-02-11 23:53:23 +01:00
######################################################
# 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)