-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGenerateVersionHeader.cmake
28 lines (24 loc) · 1.07 KB
/
GenerateVersionHeader.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
# this cmake file is part of the following project, which is licensed under
# an MIT license. Please see version.LICENSE for details.
# https://github.com/nocnokneo/cmake-git-versioning-example
if(GIT_EXECUTABLE)
get_filename_component(SRC_DIR ${SRC} DIRECTORY)
# Generate a git-describe version string from Git repository tags
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --dirty --match "v*"
WORKING_DIRECTORY ${SRC_DIR}
OUTPUT_VARIABLE GIT_DESCRIBE_VERSION
RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT GIT_DESCRIBE_ERROR_CODE)
set(INJ_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 INJ_VERSION)
set(INJ_VERSION v0.0.0-unknown)
message(WARNING "Failed to determine INJ_VERSION from Git tags. Using default version \"${INJ_VERSION}\".")
endif()
configure_file(${SRC} ${DST} @ONLY)