Skip to content

Commit

Permalink
Merge pull request #38 from antoniovazquezblanco/dev/versioning
Browse files Browse the repository at this point in the history
Add a git version detection system
  • Loading branch information
BatchDrake committed Apr 5, 2023
2 parents 7189f3f + 23456e5 commit b351905
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 16 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/cmake.yml
Expand Up @@ -37,6 +37,9 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Unshallow
run: git fetch --tags --prune --unshallow origin

- name: Get short hash
id: vars
run: cd ${{github.workspace}}/sigutils/ && echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -81,6 +84,9 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Unshallow
run: git fetch --tags --prune --unshallow origin

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON

Expand All @@ -93,13 +99,18 @@ jobs:
run:
shell: msys2 {0}
steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v2

- uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
update: true
install: mingw-w64-x86_64-cc mingw-w64-x86_64-make mingw-w64-x86_64-cmake mingw-w64-x86_64-libsndfile mingw-w64-x86_64-fftw mingw-w64-x86_64-volk

install: git mingw-w64-x86_64-cc mingw-w64-x86_64-make mingw-w64-x86_64-cmake mingw-w64-x86_64-libsndfile mingw-w64-x86_64-fftw mingw-w64-x86_64-volk

- name: Unshallow
run: git fetch --tags --prune --unshallow origin

- name: Configure CMake
run: /mingw64/bin/cmake -B '${{github.workspace}}/build' -G"MinGW Makefiles" -DCMAKE_INSTALL_PREFIX:PATH=/mingw64 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON

Expand Down
27 changes: 14 additions & 13 deletions CMakeLists.txt
Expand Up @@ -20,27 +20,28 @@

cmake_minimum_required(VERSION 3.12.0)

set(SIGUTILS_VERSION_MAJOR 0)
set(SIGUTILS_VERSION_MINOR 3)
set(SIGUTILS_VERSION_PATCH 0)
# CMake modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
include(GNUInstallDirs)
include(FindPkgConfig)
include(CodeAnalysis)
include(GitVersionDetect)

set(SIGUTILS_ABI_VERSION 1)
# Use git version detect to obtain a version
set(SIGUTILS_VERSION_MAJOR ${GITVERSIONDETECT_VERSION_MAJOR})
set(SIGUTILS_VERSION_MINOR ${GITVERSIONDETECT_VERSION_MINOR})
set(SIGUTILS_VERSION_PATCH ${GITVERSIONDETECT_VERSION_PATCH})
set(SIGUTILS_VERSION ${SIGUTILS_VERSION_MAJOR}.${SIGUTILS_VERSION_MINOR}.${SIGUTILS_VERSION_PATCH})

set(
SIGUTILS_VERSION
${SIGUTILS_VERSION_MAJOR}.${SIGUTILS_VERSION_MINOR}.${SIGUTILS_VERSION_PATCH})
# Set the ABI version manually
set(SIGUTILS_ABI_VERSION 1)

# Define the project
project(
sigutils
VERSION ${SIGUTILS_VERSION}
LANGUAGES C)

# CMake modules
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules")
include(FindPkgConfig)
include(CodeAnalysis)
include(GNUInstallDirs)

# Find requirements
find_package(Threads)
pkg_check_modules(SNDFILE REQUIRED sndfile>=1.0.2)
Expand Down
34 changes: 34 additions & 0 deletions cmake/modules/GitVersionDetect.cmake
@@ -0,0 +1,34 @@
# Required packages
find_package(Git)

# Check if a git executable was found
if(GIT_EXECUTABLE)
# Generate a git-describe version string from Git repository tags
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --dirty --match "v*"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_DESCRIBE_VERSION
RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# If no error took place, save the version
if(NOT GIT_DESCRIBE_ERROR_CODE)
set(GITVERSIONDETECT_VERSION ${GIT_DESCRIBE_VERSION})
endif()
endif()

# Final fallback: Just use a bogus version string that is semantically older
# than anything else and spit out a warning to the developer.
if(NOT DEFINED GITVERSIONDETECT_VERSION)
set(GITVERSIONDETECT_VERSION v0.0.0-unknown)
message(WARNING "Failed to determine GITVERSIONDETECT_VERSION from Git tags. Using default version \"${GITVERSIONDETECT_VERSION}\".")
endif()

# Split the version into major, minor, patch and prerelease
string(REGEX MATCH "^v([0-9]+)\\.([0-9]+)\\.([0-9]+)(-([0-9]+)-([a-z0-9]+))?"
GITVERSIONDETECT_VERSION_MATCH ${GITVERSIONDETECT_VERSION})
set(GITVERSIONDETECT_VERSION_MAJOR ${CMAKE_MATCH_1})
set(GITVERSIONDETECT_VERSION_MINOR ${CMAKE_MATCH_2})
set(GITVERSIONDETECT_VERSION_PATCH ${CMAKE_MATCH_3})
set(GITVERSIONDETECT_VERSION_COMMIT_NUM ${CMAKE_MATCH_5})
set(GITVERSIONDETECT_VERSION_COMMIT_SHA ${CMAKE_MATCH_6})

0 comments on commit b351905

Please sign in to comment.