2021-03-28 16:58:51 +02:00
# This script will set the following variables:
# GIT_HASH
# If the git binary is found and the git work tree is intact, GIT_HASH is worked out using the `git rev-parse --short HEAD` command
# The value of GIT_HASH can be overriden by defining the GIT_HASH environment variable
# GIT_COMMIT
# If the git binary is found and the git work tree is intact, GIT_COMMIT is worked out using the `git rev-parse HEAD` command
# The value of GIT_COMMIT can be overriden by defining the GIT_COMMIT environment variable
# 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
2022-06-04 21:00:42 +02:00
# 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
2021-03-28 16:58:51 +02:00
find_package ( Git )
set ( GIT_HASH "GIT-REPOSITORY-NOT-FOUND" )
set ( GIT_COMMIT "GIT-REPOSITORY-NOT-FOUND" )
set ( GIT_RELEASE "${PROJECT_VERSION}" )
2022-06-04 21:00:42 +02:00
set ( GIT_MODIFIED 0 )
2021-03-28 16:58:51 +02:00
2022-06-05 16:44:20 +02:00
if ( DEFINED ENV{CHATTERINO_SKIP_GIT_GEN} )
return ( )
endif ( )
2021-03-28 16:58:51 +02:00
if ( GIT_EXECUTABLE )
execute_process (
C O M M A N D $ { G I T _ E X E C U T A B L E } r e v - p a r s e - - i s - i n s i d e - w o r k - t r e e
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ S O U R C E _ D I R }
R E S U L T _ V A R I A B L E G I T _ R E P O S I T O R Y _ N O T _ F O U N D
2023-01-29 16:45:59 +01:00
O U T P U T _ Q U I E T
2021-03-28 16:58:51 +02:00
E R R O R _ Q U I E T
)
if ( GIT_REPOSITORY_NOT_FOUND )
set ( GIT_REPOSITORY_FOUND 0 )
else ( )
set ( GIT_REPOSITORY_FOUND 1 )
endif ( )
if ( GIT_REPOSITORY_FOUND )
execute_process (
C O M M A N D $ { G I T _ E X E C U T A B L E } r e v - p a r s e - - s h o r t H E A D
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ S O U R C E _ D I R }
O U T P U T _ V A R I A B L E G I T _ H A S H
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
)
execute_process (
C O M M A N D $ { G I T _ E X E C U T A B L E } r e v - p a r s e H E A D
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ S O U R C E _ D I R }
O U T P U T _ V A R I A B L E G I T _ C O M M I T
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
)
execute_process (
C O M M A N D $ { G I T _ E X E C U T A B L E } d e s c r i b e
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ S O U R C E _ D I R }
O U T P U T _ V A R I A B L E G I T _ R E L E A S E
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
)
2022-06-04 21:00:42 +02:00
execute_process (
C O M M A N D $ { G I T _ E X E C U T A B L E } s t a t u s - - p o r c e l a i n - z
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ S O U R C E _ D I R }
O U T P U T _ V A R I A B L E G I T _ M O D I F I E D _ O U T P U T
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
)
2021-03-28 16:58:51 +02:00
endif ( GIT_REPOSITORY_FOUND )
endif ( GIT_EXECUTABLE )
2022-06-04 21:00:42 +02:00
if ( GIT_MODIFIED_OUTPUT )
set ( GIT_MODIFIED 1 )
endif ( )
2021-03-28 16:58:51 +02:00
if ( DEFINED ENV{GIT_HASH} )
set ( GIT_HASH "$ENV{GIT_HASH}" )
endif ( )
if ( DEFINED ENV{GIT_COMMIT} )
set ( GIT_COMMIT "$ENV{GIT_COMMIT}" )
endif ( )
if ( DEFINED ENV{GIT_RELEASE} )
set ( GIT_RELEASE "$ENV{GIT_RELEASE}" )
endif ( )
2022-06-04 21:00:42 +02:00
message ( STATUS "Injected git values: ${GIT_COMMIT} (${GIT_RELEASE}) modified: ${GIT_MODIFIED}" )