Skip to content

Commit

Permalink
Setup version detection also from the Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
christofmuc committed Jan 2, 2025
1 parent 0d2f845 commit 10d0a0a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 31 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
#

BUILD_DIR?=.builds/universal_again
BUILD_TYPE=?=Debug
BUILD_TYPE?=Debug
TEAM_ID?=98WQ3X9M7Q

VERSION=2.4.4.78
# Determine the version the same way cmake does
VERSION:=$(shell cmake -P The-Orm/gitversion.cmake 2>&1 >/dev/null)

# Make sure to setup a Python that matches the universal build/fat binary or the architecture build
# This can be really messy if you have - like me - multiple versions of Python installed on the Mac.
Expand All @@ -34,7 +35,7 @@ all: configure build sign-dmg verify-signed
apple: notarize staple verify-notarization

configure:
echo "Configuring build for type $(BUILD_TYPE) in directory $(BUILD_DIR), using Python from $(PYTHON_TO_USE)"
@echo "Configuring build for type $(BUILD_TYPE) in directory $(BUILD_DIR), using Python from $(PYTHON_TO_USE)"
cmake -S . -B $(BUILD_DIR) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DPYTHON_EXECUTABLE=$(PYTHON_TO_USE) -DCODESIGN_CERTIFICATE_NAME=$(TEAM_ID)

build:
Expand Down
37 changes: 9 additions & 28 deletions The-Orm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,16 @@

cmake_minimum_required(VERSION 3.14)

find_package(Git)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --dirty=-dev --long
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE "PROJECT_VERSION_FULL"
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "Project full version: ${PROJECT_VERSION_FULL}")
else()
set(PROJECT_VERSION_FULL "unknown")
endif()

# Break up the version, number of commits, and the dev tag into parts
string(REGEX REPLACE "^([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" PROJECT_VERSION ${PROJECT_VERSION_FULL})
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+-([0-9]+).*" "\\1" PROJECT_TWEAK_VERSION ${PROJECT_VERSION_FULL})
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+-[0-9]+-g[0-9a-f]+(.*)" "\\1" PROJECT_DEV_TAG ${PROJECT_VERSION_FULL})

# If there were no new commits, PROJECT_TWEAK_VERSION will contain a hash or "-dev", so we need to set it to 0 in that case.
if(PROJECT_TWEAK_VERSION MATCHES "-g[0-9a-f]+.*")
set(PROJECT_TWEAK_VERSION 0)
endif()

# Append the tweak version if it's not 0
if(NOT PROJECT_TWEAK_VERSION EQUAL 0)
set(PROJECT_VERSION ${PROJECT_VERSION}.${PROJECT_TWEAK_VERSION})
endif()
# Get the version from our sub cmakefile
execute_process(
COMMAND sh -c "cmake -P The-Orm/gitversion.cmake >/dev/null"
ERROR_VARIABLE PROJECT_VERSION
)
# Cleanup output
string(REGEX REPLACE "^[[:space:]]+|[[:space:]]+$" "" PROJECT_VERSION "${PROJECT_VERSION}")
string(REGEX REPLACE "\n$" "" PROJECT_VERSION "${PROJECT_VERSION}")

# Start project
project(KnobKraftOrm VERSION ${PROJECT_VERSION})

# Now you can use PROJECT_DEV_TAG in your CMake scripts or in your code to handle the "-dev" part.
Expand Down
31 changes: 31 additions & 0 deletions The-Orm/gitversion.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

find_package(Git)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --dirty=-dev --long
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE "PROJECT_VERSION_FULL"
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else()
set(PROJECT_VERSION_FULL "unknown")
endif()

# Break up the version, number of commits, and the dev tag into parts
string(REGEX REPLACE "^([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" PROJECT_VERSION ${PROJECT_VERSION_FULL})
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+-([0-9]+).*" "\\1" PROJECT_TWEAK_VERSION ${PROJECT_VERSION_FULL})
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+-[0-9]+-g[0-9a-f]+(.*)" "\\1" PROJECT_DEV_TAG ${PROJECT_VERSION_FULL})

# If there were no new commits, PROJECT_TWEAK_VERSION will contain a hash or "-dev", so we need to set it to 0 in that case.
if(PROJECT_TWEAK_VERSION MATCHES "-g[0-9a-f]+.*")
set(PROJECT_TWEAK_VERSION 0)
endif()

# Append the tweak version if it's not 0
if(NOT PROJECT_TWEAK_VERSION EQUAL 0)
set(PROJECT_VERSION ${PROJECT_VERSION}.${PROJECT_TWEAK_VERSION})
endif()
cmake_policy(SET CMP0140 NEW)
message(${PROJECT_VERSION})
#return(PROPAGATE ${PROJECT_VERSION})

0 comments on commit 10d0a0a

Please sign in to comment.