Skip to content

Commit 491d0fc

Browse files
[CMake] Update versioning
Properly set version based on our git tags. For CMake's sake we use major.minor.patch For Windows dll metadata we use major.minor.build.revision and additional variables.
1 parent 4f82a6c commit 491d0fc

File tree

9 files changed

+222
-90
lines changed

9 files changed

+222
-90
lines changed

CMakeLists.txt

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,35 @@
33
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

55
cmake_minimum_required(VERSION 3.14.0 FATAL_ERROR)
6-
project(
7-
umf
8-
VERSION 0.1.0
9-
LANGUAGES C)
10-
116
# needed when UMF is used as an external project
127
set(UMF_CMAKE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
138

149
list(APPEND CMAKE_MODULE_PATH "${UMF_CMAKE_SOURCE_DIR}/cmake")
15-
include(${UMF_CMAKE_SOURCE_DIR}/cmake/helpers.cmake)
10+
include(helpers)
11+
12+
# We use semver aligned version, set via git tags. We parse git output to
13+
# establih the version of UMF to be used in CMake, Win dll's, and within the
14+
# code (e.g. in logger). We have 3-component releases (e.g. 1.5.1) plus release
15+
# candidates and git info. Function below sets all variables related to version.
16+
set_version_variables()
17+
message(STATUS "UMF version: ${UMF_VERSION}")
18+
19+
# version we set in CMake is abbreviated just to major.minor.patch
20+
project(
21+
umf
22+
VERSION ${UMF_CMAKE_VERSION}
23+
LANGUAGES C)
24+
25+
if(CMAKE_PROJECT_VERSION_PATCH GREATER 0)
26+
# set extra variable for Windows dll metadata
27+
set(UMF_VERSION_BUGFIX 1)
28+
endif()
1629

1730
include(CTest)
1831
include(CMakePackageConfigHelpers)
1932
include(GNUInstallDirs)
2033
find_package(PkgConfig)
2134

22-
# CMAKE_PROJECT_VERSION[_MAJOR|_MINOR|_PATCH] variables are set via 'project'
23-
# command. They cannot contain any "pre-release" part, though. We use custom
24-
# "UMF_SRC_VERSION" to store more accurate (source) version - this var should be
25-
# used, e.g., for creating packages.
26-
set_source_version()
27-
message(
28-
STATUS
29-
"UMF version: ${CMAKE_PROJECT_VERSION} (source version: ${UMF_SRC_VERSION})"
30-
)
31-
3235
# Build Options
3336
option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF)
3437
option(UMF_BUILD_LEVEL_ZERO_PROVIDER "Build Level Zero memory provider" ON)

RELEASE_STEPS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Do changes for a release:
4040
- Add an entry to ChangeLog, remember to change the day of the week in the release date
4141
- For major releases mention API and ABI compatibility with the previous release
4242
- Update project's version in a few places:
43-
- Set the new $VERSION in `project` function in the top-level `CMakeLists.txt`
43+
- For major and minor releases: `UMF_VERSION_CURRENT` in `include/umf/base.h` (the API version)
4444
- `release` variable in `scripts/docs_config/conf.py` (for docs)
4545
- `UMF_VERSION` variable in `.github/workflows/basic.yml` (for installation test)
4646
- For major releases update ABI version in `.map` and `.def` files

cmake/helpers.cmake

Lines changed: 139 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,68 +10,158 @@
1010
include(CheckCCompilerFlag)
1111
include(CheckCXXCompilerFlag)
1212

13-
# src version shows the current version, as reported by 'git describe', unless
14-
# 'git' is not available, then fall back to the top-level defined version
15-
function(set_source_version)
13+
# This function establishes version variables based on the git describe output.
14+
# If there's no git available in the system, the version will be set to "0.0.0".
15+
# If git reports only a hash, the version will be set to "0.0.0.git.<hash>".
16+
# Otherwise we'll use 3-component version: major.minor.patch, just for CMake's
17+
# sake. A few extra variables will be set for Win dll metadata.
18+
#
19+
# Important note: CMake does not support rc or git information. According to
20+
# semver rules, 1.5.1-rc1 should be less than 1.5.1, but it seems hard to
21+
# achieve such comparison in CMake. So, for CMake's sake we only set 3-component
22+
# version in variable "UMF_CMAKE_VERSION", ignoring the rc and git information.
23+
# It's only used to set SOVERSION and creating "umf-config.cmake" file.
24+
#
25+
# For Windows versioning in dll metadata, we use 4-component version plus a few
26+
# additional variables. REVISION has to be an integer and is calculated as:
27+
# REVISION = rc_no * 1000 + git_commit_no (commits count after the last release)
28+
#
29+
# For all other usages (beside CMake and Win dll), we use semver aligned version
30+
# "UMF_VERSION", which is in line with our tags (e.g. "1.5.0-rc2").
31+
#
32+
# Example parsing of git output:
33+
# cmake-format: off
34+
# +-----------------------+-------+-------+-------+----------+--------+---------+------------+
35+
# | \ CMake:| Major | Minor | Patch | | | | |
36+
# +-----------------------+-------+-------+-------+----------+--------+---------+------------+
37+
# | git describe \ Win32:| MAJOR | MINOR | BUILD | REVISION | BUGFIX | PRIVATE | PRERELEASE |
38+
# +-----------------------+-------+-------+-------+----------+--------+---------+------------+
39+
# | 1.5.0-rc2-0-gb8f7a32 | 1 | 5 | 0 | 2000 | | | true |
40+
# | 1.5.0-rc2 | 1 | 5 | 0 | 2000 | | | true |
41+
# | 1.5.0-rc3-6-gb8f7a32 | 1 | 5 | 0 | 3006 | | true | true |
42+
# | 1.5.0-0-gb8f7a32 | 1 | 5 | 0 | 0 | | | |
43+
# | 1.5.0 | 1 | 5 | 0 | 0 | | | |
44+
# | 1.5.0-6-123345678 | 1 | 5 | 0 | 6 | | true | |
45+
# | 1.5.2-rc1-0-gb8f7a32 | 1 | 5 | 2 | 1000 | true | | true |
46+
# | 1.5.2-rc4-6-gb8f7a32 | 1 | 5 | 2 | 4006 | true | true | true |
47+
# | 1.5.2-0-gb8f7a32 | 1 | 5 | 2 | 0 | true | | |
48+
# | 1.5.2-6-gb8f7a32 | 1 | 5 | 2 | 6 | true | true | |
49+
# | gb8f7a32 | 0 | 0 | 0 | 0 | | true | |
50+
# | ? (no git) | 0 | 0 | 0 | 0 | | true | |
51+
# +-----------------------+-------+-------+-------+----------+--------+---------+------------+
52+
# cmake-format: on
53+
function(set_version_variables)
54+
# default values
55+
set(UMF_VERSION_PRERELEASE
56+
0
57+
PARENT_SCOPE)
58+
set(UMF_VERSION_PRIVATE
59+
1
60+
PARENT_SCOPE)
61+
set(UMF_VERSION_BUGFIX
62+
0
63+
PARENT_SCOPE)
64+
set(UMF_VERSION_REVISION
65+
0
66+
PARENT_SCOPE)
67+
set(UMF_CMAKE_VERSION
68+
"0.0.0"
69+
PARENT_SCOPE)
70+
set(UMF_VERSION
71+
"0.0.0"
72+
PARENT_SCOPE)
73+
1674
execute_process(
1775
COMMAND git describe --always
1876
OUTPUT_VARIABLE GIT_VERSION
1977
WORKING_DIRECTORY ${UMF_CMAKE_SOURCE_DIR}
2078
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
2179

22-
if(GIT_VERSION)
23-
# 1.5.0 - we're on a tag
24-
string(REGEX MATCHALL "\^([0-9]+\.[0-9]+\.[0-9]+)\$" MATCHES
25-
${GIT_VERSION})
26-
if(MATCHES)
27-
set(UMF_SRC_VERSION
28-
"${CMAKE_MATCH_1}"
29-
PARENT_SCOPE)
30-
return()
31-
endif()
80+
if(NOT GIT_VERSION)
81+
# no git or it reported no version. Use default ver: "0.0.0"
82+
return()
83+
endif()
3284

33-
# 1.5.0-rc1 - we're on a RC tag
34-
string(REGEX MATCHALL "\^([0-9]+\.[0-9]+\.[0-9]+\-rc[0-9]+)\$" MATCHES
35-
${GIT_VERSION})
36-
if(MATCHES)
37-
set(UMF_SRC_VERSION
38-
"${CMAKE_MATCH_1}"
39-
PARENT_SCOPE)
40-
return()
41-
endif()
85+
# v1.5.0 - we're exactly on a tag -> UMF ver: "1.5.0"
86+
string(REGEX MATCHALL "\^v([0-9]+\.[0-9]+\.[0-9]+)\$" MATCHES
87+
${GIT_VERSION})
88+
if(MATCHES)
89+
set(UMF_VERSION
90+
"${CMAKE_MATCH_1}"
91+
PARENT_SCOPE)
92+
set(UMF_CMAKE_VERSION
93+
"${CMAKE_MATCH_1}"
94+
PARENT_SCOPE)
95+
set(UMF_VERSION_PRIVATE
96+
0
97+
PARENT_SCOPE)
98+
return()
99+
endif()
42100

43-
# 1.5.0-rc1-19-gb8f78a329 -> 1.5.0-rc1.git19.gb8f78a329
44-
string(REGEX MATCHALL "([0-9.]*)-rc([0-9]*)-([0-9]*)-([0-9a-g]*)"
45-
MATCHES ${GIT_VERSION})
46-
if(MATCHES)
47-
set(UMF_SRC_VERSION
48-
"${CMAKE_MATCH_1}-rc${CMAKE_MATCH_2}.git${CMAKE_MATCH_3}.${CMAKE_MATCH_4}"
49-
PARENT_SCOPE)
50-
return()
51-
endif()
101+
# v1.5.0-rc1 - we're on a RC tag -> UMF ver: "1.5.0-rc1"
102+
string(REGEX MATCHALL "\^v([0-9]+\.[0-9]+\.[0-9]+)-rc([0-9]+)\$" MATCHES
103+
${GIT_VERSION})
104+
if(MATCHES)
105+
set(UMF_VERSION
106+
"${CMAKE_MATCH_1}-rc${CMAKE_MATCH_2}"
107+
PARENT_SCOPE)
108+
set(UMF_CMAKE_VERSION
109+
"${CMAKE_MATCH_1}"
110+
PARENT_SCOPE)
111+
math(EXPR revision "${CMAKE_MATCH_2} * 1000")
112+
set(UMF_VERSION_REVISION
113+
${revision}
114+
PARENT_SCOPE)
115+
set(UMF_VERSION_PRERELEASE
116+
1
117+
PARENT_SCOPE)
118+
set(UMF_VERSION_PRIVATE
119+
0
120+
PARENT_SCOPE)
121+
return()
122+
endif()
52123

53-
# 1.5.0-19-gb8f78a329 -> 1.5.0-git19.gb8f78a329
54-
string(REGEX MATCHALL "([0-9.]*)-([0-9]*)-([0-9a-g]*)" MATCHES
55-
${GIT_VERSION})
56-
if(MATCHES)
57-
set(UMF_SRC_VERSION
58-
"${CMAKE_MATCH_1}-git${CMAKE_MATCH_2}.${CMAKE_MATCH_3}"
59-
PARENT_SCOPE)
60-
return()
61-
endif()
124+
# v1.5.0-rc1-19-gb8f7a32 -> UMF ver: "1.5.0-rc1.git19.gb8f7a32"
125+
string(REGEX MATCHALL "v([0-9.]*)-rc([0-9]*)-([0-9]*)-([0-9a-g]*)" MATCHES
126+
${GIT_VERSION})
127+
if(MATCHES)
128+
set(UMF_VERSION
129+
"${CMAKE_MATCH_1}-rc${CMAKE_MATCH_2}.git${CMAKE_MATCH_3}.${CMAKE_MATCH_4}"
130+
PARENT_SCOPE)
131+
set(UMF_CMAKE_VERSION
132+
"${CMAKE_MATCH_1}"
133+
PARENT_SCOPE)
134+
math(EXPR revision "${CMAKE_MATCH_2} * 1000 + ${CMAKE_MATCH_3}")
135+
set(UMF_VERSION_REVISION
136+
${revision}
137+
PARENT_SCOPE)
138+
set(UMF_VERSION_PRERELEASE
139+
1
140+
PARENT_SCOPE)
141+
return()
142+
endif()
62143

63-
# no full version is available (e.g. only a hash commit) or a pattern
64-
# was not recognized
65-
set(UMF_SRC_VERSION
66-
"${CMAKE_PROJECT_VERSION}.git.${GIT_VERSION}"
144+
# v1.5.0-19-gb8f7a32 -> UMF ver: "1.5.0-git19.gb8f7a32"
145+
string(REGEX MATCHALL "v([0-9.]*)-([0-9]*)-([0-9a-g]*)" MATCHES
146+
${GIT_VERSION})
147+
if(MATCHES)
148+
set(UMF_VERSION
149+
"${CMAKE_MATCH_1}-git${CMAKE_MATCH_2}.${CMAKE_MATCH_3}"
150+
PARENT_SCOPE)
151+
set(UMF_CMAKE_VERSION
152+
"${CMAKE_MATCH_1}"
67153
PARENT_SCOPE)
68-
else()
69-
# git reported no version. Use version set up in the top-level CMake
70-
# with a "devel" suffix
71-
set(UMF_SRC_VERSION
72-
"${CMAKE_PROJECT_VERSION}-devel"
154+
set(UMF_VERSION_REVISION
155+
${CMAKE_MATCH_2}
73156
PARENT_SCOPE)
157+
return()
74158
endif()
159+
160+
# no full version is available (e.g. only a hash commit) or a pattern was
161+
# not recognized -> UMF ver: "0.0.0.git.<hash>"
162+
set(UMF_VERSION
163+
"0.0.0.git.${GIT_VERSION}"
164+
PARENT_SCOPE)
75165
endfunction()
76166

77167
# Sets ${ret} to version of program specified by ${name} in major.minor format

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ set(UMF_SOURCES_WINDOWS libumf_windows.c)
8181
# Compile definitions for UMF library.
8282
#
8383
# TODO: Cleanup the compile definitions across all the CMake files
84-
set(UMF_PRIVATE_COMPILE_DEFINITIONS UMF_SRC_VERSION=${UMF_SRC_VERSION})
84+
set(UMF_PRIVATE_COMPILE_DEFINITIONS UMF_VERSION=${UMF_VERSION})
8585

8686
set(UMF_SOURCES_COMMON_LINUX_MACOSX
8787
provider/provider_os_memory.c

src/libumf.rc.in

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,38 @@
88

99
#include "umf/base.h"
1010

11-
#define UMF_VERNUMBERS @CMAKE_PROJECT_VERSION_MAJOR@,@CMAKE_PROJECT_VERSION_MINOR@,@CMAKE_PROJECT_VERSION_PATCH@,0
12-
#define UMF_VERSION "@CMAKE_PROJECT_VERSION_MAJOR@.@CMAKE_PROJECT_VERSION_MINOR@"
11+
#define UMF_VERNUMBERS @CMAKE_PROJECT_VERSION_MAJOR@,@CMAKE_PROJECT_VERSION_MINOR@,@CMAKE_PROJECT_VERSION_PATCH@,@UMF_VERSION_REVISION@
12+
#define UMF_VERSION "@UMF_VERSION@"
13+
14+
#ifdef _DEBUG
15+
#define VERSION_DEBUG VS_FF_DEBUG
16+
#else
17+
#define VERSION_DEBUG 0
18+
#endif
19+
20+
#if @UMF_VERSION_PRERELEASE@
21+
#define VERSION_PRERELEASE VS_FF_PRERELEASE
22+
#else
23+
#define VERSION_PRERELEASE 0
24+
#endif
25+
26+
#if @UMF_VERSION_PRIVATE@
27+
#define VERSION_PRIVATE VS_FF_PRIVATEBUILD
28+
#else
29+
#define VERSION_PRIVATE 0
30+
#endif
31+
32+
#if @UMF_VERSION_BUGFIX@
33+
#define VERSION_PATCHED VS_FF_PATCHED
34+
#else
35+
#define VERSION_PATCHED 0
36+
#endif
1337

1438
VS_VERSION_INFO VERSIONINFO
1539
FILEVERSION UMF_VERNUMBERS
1640
PRODUCTVERSION UMF_VERNUMBERS
1741
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
18-
#ifdef _DEBUG
19-
FILEFLAGS VS_FF_DEBUG
20-
#else
21-
FILEFLAGS 0
22-
#endif
42+
FILEFLAGS (VERSION_DEBUG | VERSION_PRIVATE | VERSION_PRERELEASE | VERSION_PATCHED)
2343
FILEOS VOS__WINDOWS32
2444
FILETYPE VFT_DLL
2545
FILESUBTYPE 0

src/proxy_lib/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ add_library(${PROJECT_NAME}::proxy ALIAS umf_proxy)
3939

4040
target_link_directories(umf_proxy PRIVATE ${LIBHWLOC_LIBRARY_DIRS})
4141

42-
target_compile_definitions(umf_proxy PRIVATE UMF_SRC_VERSION=${UMF_SRC_VERSION})
42+
target_compile_definitions(umf_proxy PRIVATE UMF_VERSION=${UMF_VERSION})
4343

4444
if(PROXY_LIB_USES_SCALABLE_POOL)
4545
target_compile_definitions(umf_proxy PRIVATE PROXY_LIB_USES_SCALABLE_POOL=1)

src/proxy_lib/proxy_lib.rc.in

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,38 @@
88

99
#include "umf/base.h"
1010

11-
#define UMF_VERNUMBERS @CMAKE_PROJECT_VERSION_MAJOR@,@CMAKE_PROJECT_VERSION_MINOR@,@CMAKE_PROJECT_VERSION_PATCH@,0
12-
#define UMF_VERSION "@CMAKE_PROJECT_VERSION_MAJOR@.@CMAKE_PROJECT_VERSION_MINOR@"
11+
#define UMF_VERNUMBERS @CMAKE_PROJECT_VERSION_MAJOR@,@CMAKE_PROJECT_VERSION_MINOR@,@CMAKE_PROJECT_VERSION_PATCH@,@UMF_VERSION_REVISION@
12+
#define UMF_VERSION "@UMF_VERSION@"
13+
14+
#ifdef _DEBUG
15+
#define VERSION_DEBUG VS_FF_DEBUG
16+
#else
17+
#define VERSION_DEBUG 0
18+
#endif
19+
20+
#if @UMF_VERSION_PRERELEASE@
21+
#define VERSION_PRERELEASE VS_FF_PRERELEASE
22+
#else
23+
#define VERSION_PRERELEASE 0
24+
#endif
25+
26+
#if @UMF_VERSION_PRIVATE@
27+
#define VERSION_PRIVATE VS_FF_PRIVATEBUILD
28+
#else
29+
#define VERSION_PRIVATE 0
30+
#endif
31+
32+
#if @UMF_VERSION_BUGFIX@
33+
#define VERSION_PATCHED VS_FF_PATCHED
34+
#else
35+
#define VERSION_PATCHED 0
36+
#endif
1337

1438
VS_VERSION_INFO VERSIONINFO
1539
FILEVERSION UMF_VERNUMBERS
1640
PRODUCTVERSION UMF_VERNUMBERS
1741
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
18-
#ifdef _DEBUG
19-
FILEFLAGS VS_FF_DEBUG
20-
#else
21-
FILEFLAGS 0
22-
#endif
42+
FILEFLAGS (VERSION_DEBUG | VERSION_PRIVATE | VERSION_PRERELEASE | VERSION_PATCHED)
2343
FILEOS VOS__WINDOWS32
2444
FILETYPE VFT_DLL
2545
FILESUBTYPE 0

0 commit comments

Comments
 (0)