From d4003c0a8890a9a5a63c5e8d1c3a2de5b99c1df9 Mon Sep 17 00:00:00 2001 From: huangxin Date: Tue, 28 Jun 2022 17:45:56 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0git?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E8=AF=A6=E7=BB=86=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 10 ++++++++-- srcs/libs/CMakeLists.txt | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fbce2a4..fef3d43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,13 +10,19 @@ EXECUTE_PROCESS(COMMAND git describe --tags --always --dirty=-dev if ("${GIT_TAG}" STREQUAL "") STRING(TIMESTAMP COMPILE_TIME %Y-%m-%d_%H:%M:%S) - SET(GIT_TAG ${COMPILE_TIME}) + SET(GIT_VERSION ${COMPILE_TIME}) else () + EXECUTE_PROCESS(COMMAND git rev-parse --short HEAD + OUTPUT_VARIABLE GIT_HASH) + STRING(REGEX REPLACE "\n$" "" GIT_TAG ${GIT_TAG}) + STRING(REGEX REPLACE "\n$" "" GIT_HASH ${GIT_HASH}) + + SET(GIT_VERSION ${GIT_TAG}_${GIT_HASH}) endif () -MESSAGE("Version: " ${GIT_TAG}) +MESSAGE("Version: " ${GIT_VERSION}) ADD_SUBDIRECTORY(srcs) ADD_SUBDIRECTORY(srcs/libs) diff --git a/srcs/libs/CMakeLists.txt b/srcs/libs/CMakeLists.txt index 0f81a35..aef0347 100644 --- a/srcs/libs/CMakeLists.txt +++ b/srcs/libs/CMakeLists.txt @@ -23,7 +23,7 @@ AUX_SOURCE_DIRECTORY(hardware C_SRC) SET(CMAKE_C_STANDARD 99) -ADD_DEFINITIONS(-DBUILD_VERSION="${GIT_TAG}") +ADD_DEFINITIONS(-DBUILD_VERSION="${GIT_VERSION}") LINK_LIBRARIES(${COMMON_LIBS}) ADD_LIBRARY(${LIB_PROJECT_TARGET} ${C_SRC} ${C_HEADS}) \ No newline at end of file