summaryrefslogtreecommitdiff
path: root/cmake/utils
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/utils')
-rw-r--r--cmake/utils/GenVersionHeader.cmake11
-rw-r--r--cmake/utils/GetGitHash.cmake16
2 files changed, 27 insertions, 0 deletions
diff --git a/cmake/utils/GenVersionHeader.cmake b/cmake/utils/GenVersionHeader.cmake
new file mode 100644
index 00000000..5f5821b9
--- /dev/null
+++ b/cmake/utils/GenVersionHeader.cmake
@@ -0,0 +1,11 @@
+include(${CMAKE_CURRENT_LIST_DIR}/GetGitHash.cmake)
+get_git_hash(${GIT_DIR} ${PACKAGE_VERSION_MAJOR} ${PACKAGE_VERSION_MINOR} ${PACKAGE_VERSION_PATCH} PACKAGE_VERSION_STRING)
+
+configure_file(${INPUT_FILE} ${OUTPUT_FILE}.tmp @ONLY)
+
+execute_process(
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
+ ${OUTPUT_FILE}.tmp ${OUTPUT_FILE}
+)
+
+file(REMOVE ${OUTPUT_FILE}.tmp)
diff --git a/cmake/utils/GetGitHash.cmake b/cmake/utils/GetGitHash.cmake
new file mode 100644
index 00000000..8a9be41d
--- /dev/null
+++ b/cmake/utils/GetGitHash.cmake
@@ -0,0 +1,16 @@
+function(get_git_hash WORKING_DIR VERSION_MAJ VERSION_MIN VERSION_PAT OUTPUT_VAR)
+ execute_process(
+ COMMAND git describe --always --dirty
+ WORKING_DIRECTORY ${WORKING_DIR}
+ OUTPUT_VARIABLE _hash
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_QUIET
+ )
+
+ if(NOT _hash)
+ message(WARNING "Could not determine git hash")
+ set(_hash "${VERSION_MAJ}.${VERSION_MIN}.${VERSION_PAT}-custom")
+ endif()
+
+ set(${OUTPUT_VAR} "${_hash}" PARENT_SCOPE)
+endfunction()