forked from shader-slang/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGitVersion.cmake
56 lines (54 loc) · 1.68 KB
/
GitVersion.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
find_package(Git)
# Extract a version from the latest tag matching something like v1.2.3.4
function(get_git_version var_numeric var dir)
if(NOT DEFINED ${var})
set(version_numeric "0.0.0")
set(version "0.0.0-unknown")
if(GIT_EXECUTABLE)
set(command
"${GIT_EXECUTABLE}"
-C
"${dir}"
describe
--tags
--match
v*
)
execute_process(
COMMAND ${command}
RESULT_VARIABLE result
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE version_out
)
if(NOT result EQUAL 0)
message(
WARNING
"Getting ${var} failed: ${command} returned ${result}"
)
elseif("${version_out}" MATCHES "^v(([0-9]+(\\.[0-9]+)*).*)")
set(version "${CMAKE_MATCH_1}")
set(version_numeric "${CMAKE_MATCH_2}")
else()
message(
WARNING
"Couldn't parse version (like v1.2.3 or v1.2.3-foo) from ${version_out}"
)
endif()
else()
message(
WARNING
"Couldn't find git executable to get ${var}, please use -D${var}"
)
endif()
endif()
set(${var_numeric}
${version_numeric}
CACHE STRING
"The project version numeric part, detected using git if available"
)
set(${var}
${version}
CACHE STRING
"The project version, detected using git if available"
)
endfunction()