完善版本信息

This commit is contained in:
xiongziliang 2022-11-06 00:38:14 +08:00
parent 04e2952d12
commit 44fd6b86bc
4 changed files with 18 additions and 6 deletions

View File

@ -97,11 +97,12 @@ set(LIBRARY_OUTPUT_PATH ${OUTPUT_DIR})
set(EXECUTABLE_OUTPUT_PATH ${OUTPUT_DIR}) set(EXECUTABLE_OUTPUT_PATH ${OUTPUT_DIR})
# git # git
set(COMMIT_HASH "Git_NotFound_Unkown_commit") set(COMMIT_HASH "Git_Unkown_commit")
set(BRANCH_NAME "Git_NotFound_Unkown_branch") set(COMMIT_TIME "Git_Unkown_time")
set(BRANCH_NAME "Git_Unkown_branch")
set(BUILD_TIME "") set(BUILD_TIME "")
string(TIMESTAMP BUILD_TIME "%Y-%m-%d %H:%M:%S") string(TIMESTAMP BUILD_TIME "%Y-%m-%dT%H:%M:%S")
find_package(Git QUIET) find_package(Git QUIET)
if(GIT_FOUND) if(GIT_FOUND)
@ -117,6 +118,13 @@ if(GIT_FOUND)
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
execute_process(
COMMAND ${GIT_EXECUTABLE} log --format=format:%aI -1
OUTPUT_VARIABLE COMMIT_TIME
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif() endif()
configure_file( configure_file(
@ -124,7 +132,7 @@ configure_file(
${CMAKE_CURRENT_BINARY_DIR}/version.h ${CMAKE_CURRENT_BINARY_DIR}/version.h
@ONLY) @ONLY)
message(STATUS "Git version is ${BRANCH_NAME}:${COMMIT_HASH}:${BUILD_TIME}") message(STATUS "Git version is ${BRANCH_NAME} ${COMMIT_HASH}/${COMMIT_TIME} ${BUILD_TIME}")
############################################################################## ##############################################################################

View File

@ -222,6 +222,9 @@ int start_main(int argc,char *argv[]) {
//启动异步日志线程 //启动异步日志线程
Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>()); Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());
InfoL << kServerName;
//加载配置文件,如果配置文件不存在就创建一个 //加载配置文件,如果配置文件不存在就创建一个
loadIniConfig(g_ini_file.data()); loadIniConfig(g_ini_file.data());

View File

@ -35,9 +35,9 @@ namespace mediakit {
//请遵循MIT协议勿修改服务器声明 //请遵循MIT协议勿修改服务器声明
#if !defined(ENABLE_VERSION) #if !defined(ENABLE_VERSION)
const char kServerName[] = "ZLMediaKit-6.0(build in " __DATE__ " " __TIME__ ")"; const char kServerName[] = "ZLMediaKit-7.0(build in " __DATE__ " " __TIME__ ")";
#else #else
const char kServerName[] = "ZLMediaKit(git hash:" COMMIT_HASH ",branch:" BRANCH_NAME ",build time:" __DATE__ " " __TIME__ ")"; const char kServerName[] = "ZLMediaKit(git hash:" COMMIT_HASH "/" COMMIT_TIME ",branch:" BRANCH_NAME ",build time:" BUILD_TIME ")";
#endif #endif
}//namespace mediakit }//namespace mediakit

View File

@ -2,6 +2,7 @@
#define __GIT_VERSION_H__ #define __GIT_VERSION_H__
#define COMMIT_HASH "@COMMIT_HASH@" #define COMMIT_HASH "@COMMIT_HASH@"
#define COMMIT_TIME "@COMMIT_TIME@"
#define BRANCH_NAME "@BRANCH_NAME@" #define BRANCH_NAME "@BRANCH_NAME@"
#define BUILD_TIME "@BUILD_TIME@" #define BUILD_TIME "@BUILD_TIME@"