-
Notifications
You must be signed in to change notification settings - Fork 7
/
version.cmake
27 lines (23 loc) · 1.1 KB
/
version.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
execute_process(
COMMAND git -C ${GIT_CWD} describe --always --abbrev=8 --dirty
OUTPUT_VARIABLE GIT_DESCRIBE
ERROR_QUIET)
if ("${GIT_DESCRIBE}" STREQUAL "")
set(GIT_DESCRIBE "unknown")
else()
string(STRIP "${GIT_DESCRIBE}" GIT_DESCRIBE)
endif()
set(CONTENTS "namespace ${VERSION_NAMESPACE} { const char *versionDescription = \"${GIT_DESCRIBE}\"; }")
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/version-backup/${VERSION_CPP})
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/version-backup/${VERSION_CPP} EXISTING_CONTENTS)
else()
set(EXISTING_CONTENTS "")
endif()
if ("${CONTENTS}" STREQUAL "${EXISTING_CONTENTS}")
#message("Restoring ${VERSION_NAMESPACE} ${VERSION_CPP} backup because it is still current with \"${GIT_DESCRIBE}\"")
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/version-backup/${VERSION_CPP} DESTINATION ${CMAKE_CURRENT_SOURCE_DIR})
else()
#message("Generating ${VERSION_NAMESPACE} ${VERSION_CPP} with \"${GIT_DESCRIBE}\"")
file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/${VERSION_CPP} "${CONTENTS}")
file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/version-backup/${VERSION_CPP} "${CONTENTS}")
endif()