Generate version files and integrate into build

Add CMake configure steps to produce version.h and version.sh from
templates and include the build dir for the generated header. Add
version.h.in and version.sh.in, include version.h in VulkanWidget and
use APP_VK_VERSION for the Vulkan applicationVersion. Update make_deb.sh
to source version.sh for the package version instead
This commit is contained in:
ubuntu1804 2025-11-11 17:59:09 +08:00
parent 3c52aa1ca3
commit ad3524bd23
6 changed files with 126 additions and 48 deletions

View File

@ -123,6 +123,20 @@ else()
message(STATUS "Vulkan support disabled")
endif()
# Generate version header from template (for C++ code)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/version.h"
@ONLY
)
# Generate version shell script from template (for shell scripts)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/version.sh.in"
"${CMAKE_CURRENT_SOURCE_DIR}/version.sh"
@ONLY
)
# Common source files
set(SOURCES
src/main.cpp
@ -187,6 +201,11 @@ add_executable(${PROJECT_NAME}
${HEADERS}
)
# Include build directory for generated version.h
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_BINARY_DIR}
)
# Link Qt5 libraries
target_link_libraries(${PROJECT_NAME}
Qt5::Core

View File

@ -12,13 +12,24 @@ NC='\033[0m' # No Color
# 配置变量
APP_NAME="ScreenLockDetector"
PACKAGE_NAME="ScreenLockDetector"
# 从 CMakeLists.txt 中提取版本号
VERSION=$(grep -oP '(?<=project\(ScreenLockDetector VERSION )[0-9.]+' CMakeLists.txt)
if [ -z "$VERSION" ]; then
echo -e "${RED}错误: 无法从 CMakeLists.txt 中提取版本号${NC}"
# 从自动生成的 version.sh 中读取版本号
if [ ! -f "version.sh" ]; then
echo -e "${RED}错误: version.sh 文件不存在${NC}"
echo -e "${YELLOW}请先运行 ./build.sh 生成版本文件${NC}"
exit 1
fi
echo -e "${GREEN}✓ 从 CMakeLists.txt 读取版本号: ${VERSION}${NC}"
# Source version.sh to get APP_VERSION
source version.sh
if [ -z "$APP_VERSION" ]; then
echo -e "${RED}错误: 无法从 version.sh 中读取版本号${NC}"
exit 1
fi
VERSION="$APP_VERSION"
echo -e "${GREEN}✓ 从 version.sh 读取版本号: ${VERSION}${NC}"
ARCH="amd64"
QT_DIR="$HOME/sdk/qt-5.15.2"
LINUXDEPLOYQT="${LINUXDEPLOYQT:-$HOME/tools/sunvpack-py/bin/linuxdeployqt}"

15
src/version.h.in Normal file
View File

@ -0,0 +1,15 @@
#ifndef VERSION_H
#define VERSION_H
// Auto-generated version information from CMakeLists.txt
// DO NOT EDIT THIS FILE MANUALLY - Edit CMakeLists.txt instead
#define APP_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
#define APP_VERSION_MINOR @PROJECT_VERSION_MINOR@
#define APP_VERSION_PATCH @PROJECT_VERSION_PATCH@
#define APP_VERSION_STRING "@PROJECT_VERSION@"
// Vulkan version macros
#define APP_VK_VERSION VK_MAKE_VERSION(APP_VERSION_MAJOR, APP_VERSION_MINOR, APP_VERSION_PATCH)
#endif // VERSION_H

View File

@ -1,5 +1,6 @@
#include "vulkanwidget.h"
#include "vulkanrenderer.h"
#include "version.h"
#include <QDebug>
#include <QShowEvent>
#include <QHideEvent>
@ -291,7 +292,7 @@ bool VulkanWidget::createInstance()
VkApplicationInfo appInfo = {};
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
appInfo.pApplicationName = "VulkanWidget";
appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
appInfo.applicationVersion = APP_VK_VERSION; // Auto-generated from CMakeLists.txt
appInfo.pEngineName = "No Engine";
appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
appInfo.apiVersion = VK_API_VERSION_1_0;

16
version.sh Normal file
View File

@ -0,0 +1,16 @@
#!/bin/bash
# Auto-generated version information from CMakeLists.txt
# DO NOT EDIT THIS FILE MANUALLY - Edit CMakeLists.txt instead
# This file is sourced by shell scripts to get version information
APP_VERSION_MAJOR=1
APP_VERSION_MINOR=3
APP_VERSION_PATCH=0
APP_VERSION="1.3.0"
# Export for use in other scripts
export APP_VERSION_MAJOR
export APP_VERSION_MINOR
export APP_VERSION_PATCH
export APP_VERSION

16
version.sh.in Normal file
View File

@ -0,0 +1,16 @@
#!/bin/bash
# Auto-generated version information from CMakeLists.txt
# DO NOT EDIT THIS FILE MANUALLY - Edit CMakeLists.txt instead
# This file is sourced by shell scripts to get version information
APP_VERSION_MAJOR=@PROJECT_VERSION_MAJOR@
APP_VERSION_MINOR=@PROJECT_VERSION_MINOR@
APP_VERSION_PATCH=@PROJECT_VERSION_PATCH@
APP_VERSION="@PROJECT_VERSION@"
# Export for use in other scripts
export APP_VERSION_MAJOR
export APP_VERSION_MINOR
export APP_VERSION_PATCH
export APP_VERSION