-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathext_script_git_version.cmake
More file actions
47 lines (39 loc) · 1.23 KB
/
ext_script_git_version.cmake
File metadata and controls
47 lines (39 loc) · 1.23 KB
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
# Copyright - 2019 - Jan Christoph Uhde <Jan@UhdeJC.com>
cmake_minimum_required(VERSION 3.8)
if(NOT EXT_GIT_VERSION_OUT_FILE)
set(EXT_GIT_VERSION_OUT_FILE "${CMAKE_CURRENT_LIST_DIR}/version.h")
endif()
message(STATUS "extINFO -- Trying to write version.h to: ${EXT_GIT_VERSION_OUT_FILE}")
execute_process(
COMMAND git rev-parse HEAD
OUTPUT_VARIABLE GIT_REV
ERROR_QUIET
)
if ("${GIT_REV}" STREQUAL "")
set(GIT_REV "not available")
set(GIT_BRANCH "not available")
message("could not get git revision:(")
else()
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
OUTPUT_VARIABLE GIT_BRANCH
)
string(STRIP "${GIT_REV}" GIT_REV)
string(STRIP "${GIT_BRANCH}" GIT_BRANCH)
message("found git revision: " ${GIT_REV})
message("found git branch: " ${GIT_BRANCH})
endif()
set(VERSION_INFO "
#pragma once
constexpr char const* GIT_REV=\"${GIT_REV}\";
constexpr char const* GIT_BRANCH=\"${GIT_BRANCH}\";
"
)
if(EXISTS ${EXT_GIT_VERSION_OUT_FILE})
file(READ ${EXT_GIT_VERSION_OUT_FILE} OLD_VERSION_INFO)
else()
set(OLD_VERSION_INFO "")
endif()
if (NOT "${VERSION_INFO}" STREQUAL "${OLD_VERSION_INFO}")
file(WRITE ${EXT_GIT_VERSION_OUT_FILE} "${VERSION_INFO}")
endif()