Organized version information (#3781)

added new `GIT_MODIFIED` variable - used to determine whether the vcs tree was compiled or not at the time of building the app
added information about running in DEBUG mode which might be very helpful to determine whether one is running a DEBUG build, e.g. in the process of troubleshooting/determining crash causes

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
Kasia
2022-06-04 21:00:42 +02:00
committed by GitHub
parent a693bc23f8
commit a7939b727f
6 changed files with 145 additions and 83 deletions
+16 -1
View File
@@ -8,12 +8,16 @@
# GIT_RELEASE
# If the git binary is found and the git work tree is intact, GIT_RELEASE is worked out using the `git describe` command
# The value of GIT_RELEASE can be overriden by defining the GIT_RELEASE environment variable
# GIT_MODIFIED
# If the git binary is found and the git work tree is intact, GIT_MODIFIED is worked out by checking if output of `git status --porcelain -z` command is empty
# The value of GIT_MODIFIED cannot be overriden
find_package(Git)
set(GIT_HASH "GIT-REPOSITORY-NOT-FOUND")
set(GIT_COMMIT "GIT-REPOSITORY-NOT-FOUND")
set(GIT_RELEASE "${PROJECT_VERSION}")
set(GIT_MODIFIED 0)
if (GIT_EXECUTABLE)
execute_process(
@@ -49,9 +53,20 @@ if (GIT_EXECUTABLE)
OUTPUT_VARIABLE GIT_RELEASE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${GIT_EXECUTABLE} status --porcelain -z
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_MODIFIED_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif (GIT_REPOSITORY_FOUND)
endif (GIT_EXECUTABLE)
if (GIT_MODIFIED_OUTPUT)
set(GIT_MODIFIED 1)
endif ()
if (DEFINED ENV{GIT_HASH})
set(GIT_HASH "$ENV{GIT_HASH}")
endif ()
@@ -62,4 +77,4 @@ if (DEFINED ENV{GIT_RELEASE})
set(GIT_RELEASE "$ENV{GIT_RELEASE}")
endif ()
message(STATUS "Injected git values: ${GIT_COMMIT} (${GIT_RELEASE}) ${GIT_HASH}")
message(STATUS "Injected git values: ${GIT_COMMIT} (${GIT_RELEASE}) modified: ${GIT_MODIFIED}")