forked from crux-toolkit/crux-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-version-header.cmake
47 lines (40 loc) · 1.44 KB
/
make-version-header.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
set(CRUX_VERSION_FULL "${CRUX_VERSION}")
if (EXISTS "${SOURCE_DIR}/.git/HEAD")
# Add the git hash
execute_process(
COMMAND "git" "rev-parse" "--short" "HEAD"
WORKING_DIRECTORY ${SOURCE_DIR}
RESULT_VARIABLE GIT_RESULT
OUTPUT_VARIABLE PROJECT_SOURCE_VERSION
)
if (GIT_RESULT EQUAL 0)
string(
REGEX REPLACE "\n$" ""
PROJECT_SOURCE_VERSION
${PROJECT_SOURCE_VERSION}
)
set(CRUX_VERSION_FULL "${CRUX_VERSION_FULL}-${PROJECT_SOURCE_VERSION}")
else (GIT_RESULT EQUAL 0)
MESSAGE("Git command git show-ref failed: ${PROJECT_SOURCE_VERSION}")
endif (GIT_RESULT EQUAL 0)
# Add the last commit date
execute_process(
COMMAND "git" "log" "-1" "--format=%cd" "--date=short"
WORKING_DIRECTORY ${SOURCE_DIR}
RESULT_VARIABLE GIT_DATE_RESULT
OUTPUT_VARIABLE PROJECT_COMMIT_DATE
)
if (GIT_DATE_RESULT EQUAL 0)
string(
REGEX REPLACE "\n$" ""
PROJECT_COMMIT_DATE
${PROJECT_COMMIT_DATE}
)
set(CRUX_VERSION_FULL "${CRUX_VERSION_FULL}-${PROJECT_COMMIT_DATE}")
else (GIT_DATE_RESULT EQUAL 0)
MESSAGE("Git command git show-ref failed: ${PROJECT_COMMIT_DATE}")
endif (GIT_DATE_RESULT EQUAL 0)
endif (EXISTS "${SOURCE_DIR}/.git/HEAD")
file(WRITE crux_version.h.txt "#define CRUX_VERSION \"${CRUX_VERSION_FULL}\"\n")
# Copy the file to the final header if the version changed
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different crux_version.h.txt crux_version.h)