From d8a01504a3b4a4bf45f4cb0f7b0488d15361e2f1 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Tue, 4 Mar 2025 12:17:19 +0200 Subject: [PATCH] chore: Add support for Qt Creator version to the plugin build script (#87) This will allow to add code conditional on the Qt Creator version to the plugin codebase. The Qt Creator version will be passed from the build script automatically. This will also allow to easily extend the Github Actions job matrix to create releases for more than one Qt Creator version. Using QT_VERSION_CHECK allows to reuse existing Qt patterns of checking versions. Code has been tested by invoking QODEASSIST_QT_CREATOR_VERSION in code. --- .github/workflows/build_cmake.yml | 12 ++++++++++++ CMakeLists.txt | 6 ++++++ Version.hpp | 28 ++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 Version.hpp diff --git a/.github/workflows/build_cmake.yml b/.github/workflows/build_cmake.yml index 33f1a2b..c24165d 100644 --- a/.github/workflows/build_cmake.yml +++ b/.github/workflows/build_cmake.yml @@ -187,6 +187,15 @@ jobs: set(ENV{CXX} ${{ matrix.config.cxx }}) set(ENV{MACOSX_DEPLOYMENT_TARGET} "${{ env.MACOS_DEPLOYMENT_TARGET }}") + string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)" version_match "$ENV{QT_CREATOR_VERSION}") + set(QT_CREATOR_VERSION_MAJOR "${CMAKE_MATCH_1}") + set(QT_CREATOR_VERSION_MINOR "${CMAKE_MATCH_2}") + set(QT_CREATOR_VERSION_PATCH "${CMAKE_MATCH_3}") + + if(NOT version_match) + message(FATAL_ERROR "Failed to parse Qt Creator version string: $ENV{QT_CREATOR_VERSION}") + endif() + if ("${{ runner.os }}" STREQUAL "Windows" AND NOT "x${{ matrix.config.environment_script }}" STREQUAL "x") execute_process( COMMAND "${{ matrix.config.environment_script }}" && set @@ -223,6 +232,9 @@ jobs: --qt-path "${{ steps.qt.outputs.qt_dir }}" --qtc-path "${{ steps.qt_creator.outputs.qtc_dir }}" --output-path "$ENV{GITHUB_WORKSPACE}" + --add-config=-DQODEASSIST_QT_CREATOR_VERSION_MAJOR=${QT_CREATOR_VERSION_MAJOR} + --add-config=-DQODEASSIST_QT_CREATOR_VERSION_MINOR=${QT_CREATOR_VERSION_MINOR} + --add-config=-DQODEASSIST_QT_CREATOR_VERSION_PATCH=${QT_CREATOR_VERSION_PATCH} RESULT_VARIABLE result ) if (NOT result EQUAL 0) diff --git a/CMakeLists.txt b/CMakeLists.txt index f1535fe..7cc1f76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,12 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) find_package(QtCreator REQUIRED COMPONENTS Core) find_package(Qt6 COMPONENTS Core Gui Quick Widgets Network REQUIRED) +add_definitions( + -DQODEASSIST_QT_CREATOR_VERSION_MAJOR=${QODEASSIST_QT_CREATOR_VERSION_MAJOR} + -DQODEASSIST_QT_CREATOR_VERSION_MINOR=${QODEASSIST_QT_CREATOR_VERSION_MINOR} + -DQODEASSIST_QT_CREATOR_VERSION_PATCH=${QODEASSIST_QT_CREATOR_VERSION_PATCH} +) + add_subdirectory(llmcore) add_subdirectory(settings) add_subdirectory(logger) diff --git a/Version.hpp b/Version.hpp new file mode 100644 index 0000000..75a466a --- /dev/null +++ b/Version.hpp @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2025 Povilas Kanapickas + * + * This file is part of QodeAssist. + * + * QodeAssist is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * QodeAssist is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with QodeAssist. If not, see . + */ + +#pragma once + +#include + +#define QODEASSIST_QT_CREATOR_VERSION \ + QT_VERSION_CHECK( \ + QODEASSIST_QT_CREATOR_VERSION_MAJOR, \ + QODEASSIST_QT_CREATOR_VERSION_MINOR, \ + QODEASSIST_QT_CREATOR_VERSION_PATCH)