From 8cb4748a369d2bdd6c1245136a6db752f8f86719 Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Sat, 27 Jul 2024 10:51:51 -0400 Subject: [PATCH] build: Get version from git --- .github/workflows/cmake.yml | 3 +++ CMakeLists.txt | 40 ++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 4275c48..21bbf00 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -33,6 +33,9 @@ jobs: steps: - name: Checkout Code uses: actions/checkout@v4 + with: + fetch-depth: 0 + - run: git fetch --tags --force - name: Install Qt uses: jurplel/install-qt-action@v4 diff --git a/CMakeLists.txt b/CMakeLists.txt index b87f25c..752aa1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,43 @@ cmake_minimum_required(VERSION 3.16) -project(QtAwesome) + +#Set The Current Version Number to use as fallback if GIT Fails. +set(QTAWESOME_VERSION_MAJOR 6) +set(QTAWESOME_VERSION_MINOR 5) +set(QTAWESOME_VERSION_PATCH 1) +set(QTAWESOME_VERSION_TWEAK 0) +# Get the version from git if it's a git repository +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git) + find_package(Git) + if(GIT_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} describe --tags --long --match "font-awesome-*" --always + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + OUTPUT_VARIABLE GITREV + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + string(FIND ${GITREV} "font-awesome-" isRev) + if(NOT ifRev EQUAL -1) + string(REGEX MATCH [0-9]+ MAJOR ${GITREV}) + string(REGEX MATCH \\.[0-9]+ MINOR ${GITREV}) + string(REPLACE "." "" MINOR "${MINOR}") + string(REGEX MATCH [0-9]+\- PATCH ${GITREV}) + string(REPLACE "-" "" PATCH "${PATCH}") + string(REGEX MATCH \-[0-9]+\- TWEAK ${GITREV}) + string(REPLACE "-" "" TWEAK "${TWEAK}") + set(QTAWESOME_VERSION_MAJOR ${MAJOR}) + set(QTAWESOME_VERSION_MINOR ${MINOR}) + set(QTAWESOME_VERSION_PATCH ${PATCH}) + set(QTAWESOME_VERSION_TWEAK ${TWEAK}) + elseif(NOT ${GITREV} STREQUAL "") + set(QTAWESOME_VERSION_TWEAK ${GITREV}) + endif() + endif() +endif() + +set(QTAWESOME_VERSION "${QTAWESOME_VERSION_MAJOR}.${QTAWESOME_VERSION_MINOR}.${QTAWESOME_VERSION_PATCH}.${QTAWESOME_VERSION_TWEAK}") +message(STATUS "Building QTAWESOME: ${QTAWESOME_VERSION}") + +project(QtAwesome VERSION ${QTAWESOME_VERSION}) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets)