summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorSimon Rettberg2020-12-02 12:54:27 +0100
committerSimon Rettberg2020-12-02 12:54:27 +0100
commit656e776498fe862b1b388435568c5bb72213cb16 (patch)
tree855d21b40e4ccb9c07664e4922632da2a883d99d /cmake
parent[CLIENT] print help and version number correctly (diff)
downloaddnbd3-656e776498fe862b1b388435568c5bb72213cb16.tar.gz
dnbd3-656e776498fe862b1b388435568c5bb72213cb16.tar.xz
dnbd3-656e776498fe862b1b388435568c5bb72213cb16.zip
[BUILD] Include branch and build timestamp in binaries
Diffstat (limited to 'cmake')
-rw-r--r--cmake/GenerateBuild.cmake1
-rw-r--r--cmake/Version.cmake19
2 files changed, 13 insertions, 7 deletions
diff --git a/cmake/GenerateBuild.cmake b/cmake/GenerateBuild.cmake
index 020eb84..96b2906 100644
--- a/cmake/GenerateBuild.cmake
+++ b/cmake/GenerateBuild.cmake
@@ -5,6 +5,7 @@
# set current build type of the project
set(DNBD3_BUILD ${BUILD_TYPE})
+string(TIMESTAMP DNBD3_BUILD_DATE "%Y-%m-%d" UTC)
# write dnbd3 build type into a new C source file based on the specified build file template
configure_file(${BUILD_INPUT_FILE_TEMPLATE} ${BUILD_OUTPUT_FILE})
diff --git a/cmake/Version.cmake b/cmake/Version.cmake
index 5f63a31..75e99e3 100644
--- a/cmake/Version.cmake
+++ b/cmake/Version.cmake
@@ -36,7 +36,7 @@ macro(get_repository_version REPOSITORY_VERSION VERSION_HEADER_FILE VERSION_BUIL
if(EXISTS ${VERSION_HEADER_FILE})
# get version information from the generated version header of the source package
file(READ ${VERSION_HEADER_FILE} GIT_VERSION)
- string(REGEX MATCH "\"(([0-9]+:)?[0-9][A-Za-z0-9.+~-]*)\"" GIT_VERSION ${GIT_VERSION})
+ string(REGEX MATCH "DNBD3_VERSION\s+\"([0-9][A-Za-z0-9.+~-]*)\"" GIT_VERSION ${GIT_VERSION})
set(GIT_VERSION "${CMAKE_MATCH_1}")
else(EXISTS ${VERSION_HEADER_FILE})
# get detailed Git version information from Git repository
@@ -44,14 +44,18 @@ macro(get_repository_version REPOSITORY_VERSION VERSION_HEADER_FILE VERSION_BUIL
WORKING_DIRECTORY ${REPOSITORY_DIR}
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
-
- # remove the first letter of the version to satisfy packaging rules
- string(REGEX MATCH "([0-9]+:)?[0-9][A-Za-z0-9.+~-]*" GIT_VERSION ${GIT_VERSION})
+ execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
+ WORKING_DIRECTORY ${REPOSITORY_DIR}
+ OUTPUT_VARIABLE GIT_BRANCH
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
# overwrite version from Git if version is unknown
if(GIT_VERSION STREQUAL "")
set(GIT_VERSION "unknown")
endif(GIT_VERSION STREQUAL "")
+ if(GIT_BRANCH STREQUAL "")
+ set(GIT_BRANCH "unknown")
+ endif(GIT_BRANCH STREQUAL "")
# get status of Git repository
execute_process(COMMAND ${GIT_EXECUTABLE} status --porcelain
@@ -62,7 +66,7 @@ macro(get_repository_version REPOSITORY_VERSION VERSION_HEADER_FILE VERSION_BUIL
# check if Git repository is dirty
if(NOT GIT_STATUS STREQUAL "")
# the Git repository is dirty, thus extend the version information
- set(GIT_VERSION "${GIT_VERSION}-modified")
+ set(GIT_VERSION "${GIT_VERSION}+MOD")
# print a message in Release build configuration to warn about the dirty repository
if(${VERSION_BUILD_TYPE} MATCHES "Release")
@@ -71,6 +75,7 @@ macro(get_repository_version REPOSITORY_VERSION VERSION_HEADER_FILE VERSION_BUIL
endif(NOT GIT_STATUS STREQUAL "")
endif(EXISTS ${VERSION_HEADER_FILE})
- # return version to caller
- set(${REPOSITORY_VERSION} ${GIT_VERSION})
+ # remove the first letter of the version to satisfy packaging rules
+ # and return to caller
+ string(REGEX MATCH "([0-9]+:)?[0-9][A-Za-z0-9.+~-]*" ${REPOSITORY_VERSION} ${GIT_VERSION})
endmacro(get_repository_version)