增加自动版本标记脚本,从Tag中提取版本号,自动生成nm | grep VERSION方式查看的版本号。

This commit is contained in:
Lu Qiuwen
2018-10-11 20:08:22 +08:00
parent 72b931b02a
commit 70fbff5b7d
8 changed files with 1383 additions and 0 deletions

47
cmake/Version.cmake Normal file
View File

@@ -0,0 +1,47 @@
# Using autorevision.sh to generate version information
set(__SOURCE_AUTORESIVISION ${CMAKE_SOURCE_DIR}/autorevision.sh)
set(__AUTORESIVISION ${CMAKE_BINARY_DIR}/autorevision.sh)
set(__VERSION_CACHE ${CMAKE_SOURCE_DIR}/version.txt)
set(__VERSION_CONFIG ${CMAKE_BINARY_DIR}/version.cmake)
file(COPY ${__SOURCE_AUTORESIVISION} DESTINATION ${CMAKE_BINARY_DIR}
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)
# execute autorevision.sh to generate version information
execute_process(COMMAND ${__AUTORESIVISION} -t cmake -o ${__VERSION_CACHE} OUTPUT_FILE ${__VERSION_CONFIG} ERROR_QUIET)
include(${__VERSION_CONFIG})
# extract major, minor, patch version from git tag
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" TFE_VERSION_MAJOR "${VCS_TAG}")
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" TFE_VERSION_MINOR "${VCS_TAG}")
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" TFE_VERSION_PATCH "${VCS_TAG}")
if(NOT TFE_VERSION_MAJOR)
set(TFE_VERSION_MAJOR 3)
endif()
if(NOT TFE_VERSION_MINOR)
set(TFE_VERSION_MINOR 0)
endif()
if(NOT TFE_VERSION_PATCH)
set(TFE_VERSION_PATCH 0)
endif()
set(TFE_VERSION "${TFE_VERSION_MAJOR}.${TFE_VERSION_MINOR}.${TFE_VERSION_PATCH}")
set(TFE_DESCRIBE "${VCS_SHORT_HASH}")
set(TFE_GIT_VERSION "${TFE_VERSION_MAJOR}.${TFE_VERSION_MINOR}.${TFE_VERSION_PATCH}-${TFE_VERSION_BUILD}")
set(TFE_VAR_VERSION "${TFE_VERSION_MAJOR}_${TFE_VERSION_MINOR}_${TFE_VERSION_PATCH}_${TFE_DESCRIBE}")
# system information
execute_process(COMMAND uname -r OUTPUT_VARIABLE TFE_VERSION_KERNEL)
# print information
message(STATUS "TFE Version: ${TFE_GIT_VERSION}")
message(STATUS "Kernel Version: ${TFE_VERSION_KERNEL}")
add_definitions(-DTFE_GIT_VERSION=\"${TFE_GIT_VERSION}\")
add_definitions(-DTFE_VAR_VERSION=${TFE_VAR_VERSION})