fix: cmake version.txt generation in non-git environments

This was not well defined.
This commit is contained in:
shenleban tongying 2023-07-30 01:21:14 -04:00
parent 92ee08b093
commit 67f5b1333b
No known key found for this signature in database
3 changed files with 15 additions and 13 deletions

View file

@ -42,16 +42,19 @@ find_package(Qt6 REQUIRED COMPONENTS
#### Compile time files and preprocessor flags
# Obtain git commit hash
execute_process(
COMMAND git rev-parse --short=8 HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(TIMESTAMP date_for_version_file) # note: this variable is cached for every run, but for user installation, this doesn't matter much
configure_file(version.txt.in ${CMAKE_SOURCE_DIR}/version.txt)
block() # generate version.txt
string(TIMESTAMP build_time)
find_package(Git)
if (EXISTS "${CMAKE_SOURCE_DIR}/.git" AND GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} -C "${CMAKE_SOURCE_DIR}" rev-parse --short HEAD
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE GIT_HASH)
file(WRITE "${CMAKE_SOURCE_DIR}/version.txt" "${PROJECT_VERSION}.${GIT_HASH} at ${build_time}")
else () # not built in a git repo
file(WRITE "${CMAKE_SOURCE_DIR}/version.txt" "${PROJECT_VERSION} at ${build_time}")
endif ()
endblock()
#### Sources Files

View file

@ -17,8 +17,8 @@ QString version()
QString everything()
{
return QStringLiteral( "Goldendict-ng " ) + Version::version() + "\n" + "Qt " + QLatin1String( qVersion() ) + " "
+ Version::compiler + QSysInfo::productType() + " " + QSysInfo::kernelType() + " " + QSysInfo::kernelVersion() + " "
+ QSysInfo::buildAbi() + "\n" + "Flags:" + flags;
+ Version::compiler + " " + QSysInfo::productType() + " " + QSysInfo::kernelType() + " " + QSysInfo::kernelVersion()
+ " " + QSysInfo::buildAbi() + "\n" + "Flags:" + flags;
}
} // namespace Version

View file

@ -1 +0,0 @@
${PROJECT_VERSION}.${GIT_HASH} on ${date_for_version_file}