From 2e813851a13cb2040a7ea5d7cf08aef2648930bb Mon Sep 17 00:00:00 2001 From: Thomas Lamy Date: Sun, 1 Mar 2026 11:28:00 +0100 Subject: [PATCH] build: embed version string in all platform artifacts - Add APP_VERSION cmake variable (parsed from x.y.z into MAJOR/MINOR/PATCH) - macOS: set CFBundleShortVersionString/CFBundleVersion via cmake bundle properties and bundle_macos.sh Info.plist generation - Linux/DEB: CPACK_PACKAGE_VERSION now uses APP_VERSION instead of hardcoded 1.0.0 - Windows: generate P2ProViewer.rc from template (src/P2ProViewer.rc.in) with VERSIONINFO and icon resource; icon converted from icon.png in CI - CI: add determine-version job that runs semantic-release --dry-run on main (fallback: last git tag) and passes the result to all build jobs Co-Authored-By: Claude Sonnet 4.6 --- .github/workflows/build.yml | 47 ++++++++++++++++++++++++++++++++++--- CMakeLists.txt | 23 +++++++++++++++++- bundle_macos.sh | 4 ++++ src/P2ProViewer.rc.in | 30 +++++++++++++++++++++++ 4 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 src/P2ProViewer.rc.in diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 665697a..fb0f8d6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,8 +9,43 @@ on: pull_request: jobs: + determine-version: + name: Determine Version + runs-on: ubuntu-latest + outputs: + version: ${{ steps.get_version.outputs.version }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 'lts/*' + + - name: Install semantic-release dependencies + run: npm install + + - name: Get next version + id: get_version + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then + DRY=$(npx semantic-release --dry-run 2>&1 || true) + VERSION=$(echo "$DRY" | grep -oP '(?<=The next release version is )[0-9]+\.[0-9]+\.[0-9]+' | head -1) + fi + if [ -z "$VERSION" ]; then + VERSION=$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//' || echo "0.0.0") + fi + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "Determined version: $VERSION" + build-linux: name: Build Linux + needs: [determine-version] runs-on: ubuntu-latest steps: - name: Checkout code @@ -39,7 +74,7 @@ jobs: else BUILD_TYPE="Debug" fi - cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE + cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DAPP_VERSION=${{ needs.determine-version.outputs.version }} make -j$(nproc) - name: Package with CPack @@ -57,6 +92,7 @@ jobs: build-macos: name: Build macOS + needs: [determine-version] runs-on: macos-latest steps: - name: Checkout code @@ -75,14 +111,14 @@ jobs: else BUILD_TYPE="Debug" fi - cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE + cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DAPP_VERSION=${{ needs.determine-version.outputs.version }} make -j$(sysctl -n hw.ncpu) - name: Create App Bundle if: github.event_name == 'push' && github.ref == 'refs/heads/main' run: | chmod +x bundle_macos.sh - BUILD_DIR="build" ./bundle_macos.sh + BUILD_DIR="build" APP_VERSION="${{ needs.determine-version.outputs.version }}" ./bundle_macos.sh - name: Create DMG if: github.event_name == 'push' && github.ref == 'refs/heads/main' @@ -108,11 +144,15 @@ jobs: build-windows: name: Build Windows + needs: [determine-version] runs-on: windows-latest steps: - name: Checkout code uses: actions/checkout@v4 + - name: Convert icon to .ico + run: magick "Resources/icon.png" -define icon:auto-resize=256,128,64,48,32,16 "Resources/P2ProViewer.ico" + - name: Initialize vcpkg shell: pwsh run: | @@ -131,6 +171,7 @@ jobs: } cmake -S . -B build ` -DCMAKE_BUILD_TYPE=$build_type ` + -DAPP_VERSION="${{ needs.determine-version.outputs.version }}" ` -DUSE_FFMPEG=OFF ` -DVCPKG_TARGET_TRIPLET=x64-windows ` -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" diff --git a/CMakeLists.txt b/CMakeLists.txt index e98b947..470acf8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,18 @@ project(P2ProViewer) set(CMAKE_CXX_STANDARD 17) +if(DEFINED APP_VERSION AND NOT APP_VERSION STREQUAL "") + string(REPLACE "." ";" _ver_list "${APP_VERSION}") + list(GET _ver_list 0 APP_VERSION_MAJOR) + list(GET _ver_list 1 APP_VERSION_MINOR) + list(GET _ver_list 2 APP_VERSION_PATCH) +else() + set(APP_VERSION "0.0.0") + set(APP_VERSION_MAJOR 0) + set(APP_VERSION_MINOR 0) + set(APP_VERSION_PATCH 0) +endif() + if(WIN32 AND NOT DEFINED USE_FFMPEG) set(USE_FFMPEG OFF CACHE BOOL "Use FFmpeg for video recording") else() @@ -101,6 +113,8 @@ if (APPLE) set_target_properties(P2ProViewer PROPERTIES MACOSX_BUNDLE TRUE MACOSX_BUNDLE_ICON_FILE P2ProViewer.icns + MACOSX_BUNDLE_SHORT_VERSION_STRING "${APP_VERSION}" + MACOSX_BUNDLE_BUNDLE_VERSION "${APP_VERSION}" ) set_source_files_properties(Resources/P2ProViewer.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources) elseif(WIN32) @@ -119,6 +133,13 @@ elseif(WIN32) list(APPEND WIN32_SOURCES src/VideoRecorder_win.cpp) endif() + configure_file( + "${CMAKE_SOURCE_DIR}/src/P2ProViewer.rc.in" + "${CMAKE_BINARY_DIR}/P2ProViewer.rc" + @ONLY + ) + list(APPEND WIN32_SOURCES "${CMAKE_BINARY_DIR}/P2ProViewer.rc") + add_executable(P2ProViewer ${WIN32_SOURCES}) target_link_libraries(P2ProViewer @@ -261,7 +282,7 @@ endif() set(CPACK_PACKAGE_NAME "P2ProViewer") set(CPACK_PACKAGE_VENDOR "P2Pro") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Viewer for P2 Pro thermal camera") -set(CPACK_PACKAGE_VERSION "1.0.0") # Will be overridden by semantic-release if needed, but good to have a default +set(CPACK_PACKAGE_VERSION "${APP_VERSION}") set(CPACK_DEBIAN_PACKAGE_MAINTAINER "P2Pro Maintainer") set(CPACK_DEBIAN_PACKAGE_DEPENDS "libsdl2-2.0-0, libsdl2-ttf-2.0-0, libusb-1.0-0, libavcodec58 | libavcodec59 | libavcodec60, libavformat58 | libavformat59 | libavformat60, libswscale5 | libswscale6 | libswscale7, libavutil56 | libavutil57 | libavutil58") set(CPACK_GENERATOR "DEB") diff --git a/bundle_macos.sh b/bundle_macos.sh index c7c7a9c..2efea8e 100755 --- a/bundle_macos.sh +++ b/bundle_macos.sh @@ -63,6 +63,10 @@ cat < "$TARGET.app/Contents/Info.plist" APPL CFBundleSignature ???? + CFBundleShortVersionString + ${APP_VERSION:-0.0.0} + CFBundleVersion + ${APP_VERSION:-0.0.0} EOF diff --git a/src/P2ProViewer.rc.in b/src/P2ProViewer.rc.in new file mode 100644 index 0000000..4e7f541 --- /dev/null +++ b/src/P2ProViewer.rc.in @@ -0,0 +1,30 @@ +#include + +IDI_APPICON ICON "@CMAKE_SOURCE_DIR@/Resources/P2ProViewer.ico" + +VS_VERSION_INFO VERSIONINFO + FILEVERSION @APP_VERSION_MAJOR@,@APP_VERSION_MINOR@,@APP_VERSION_PATCH@,0 + PRODUCTVERSION @APP_VERSION_MAJOR@,@APP_VERSION_MINOR@,@APP_VERSION_PATCH@,0 + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK + FILEFLAGS 0x0L + FILEOS VOS__WINDOWS32 + FILETYPE VFT_APP + FILESUBTYPE VFT2_UNKNOWN +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "FileDescription", "P2Pro Thermal Camera Viewer\0" + VALUE "FileVersion", "@APP_VERSION@\0" + VALUE "InternalName", "P2ProViewer\0" + VALUE "OriginalFilename", "P2ProViewer.exe\0" + VALUE "ProductName", "P2ProViewer\0" + VALUE "ProductVersion", "@APP_VERSION@\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END