Skip to content

Commit e20139c

Browse files
committed
Get the version number from latest release tag
1 parent d6bf786 commit e20139c

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

CMakeLists.txt

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,31 @@
22
# Licensed under the MIT License.
33

44
cmake_minimum_required(VERSION 3.8.2)
5-
project(cppgraphqlgen VERSION 3.2.0)
5+
6+
file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/version.txt" VERSION_FILE)
7+
8+
# Get the latest release tag from git if possible.
9+
execute_process(COMMAND git describe --tags --long
10+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
11+
OUTPUT_VARIABLE LATEST_VERSION_TAG
12+
ERROR_QUIET
13+
OUTPUT_STRIP_TRAILING_WHITESPACE)
14+
15+
if("${LATEST_VERSION_TAG}" MATCHES "^v([0-9]+\\.[0-9]+\\.[0-9]+)-[0-9]+-[0-9a-z]+$")
16+
# The latest tag matched the pattern we expected, extract the version number.
17+
set(LATEST_VERSION "${CMAKE_MATCH_1}")
18+
message(STATUS "Latest tagged release: v${LATEST_VERSION}")
19+
20+
# Update version.txt so source archives without the release tags can still get the same version.
21+
file(WRITE "${VERSION_FILE}" "${LATEST_VERSION}")
22+
else()
23+
# Just read the last updated version from version.txt.
24+
file(READ "${VERSION_FILE}" LATEST_VERSION)
25+
endif()
26+
27+
message(STATUS "Latest version: ${LATEST_VERSION}")
28+
29+
project(cppgraphqlgen VERSION ${LATEST_VERSION})
630

731
set(CMAKE_CXX_STANDARD 17)
832

version.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.2.3

0 commit comments

Comments
 (0)