improve git-hash cmake script to detect pre-commit changes properly
This commit is contained in:
parent
1d9fb74368
commit
ac3efc6f3f
@ -1,19 +1,21 @@
|
|||||||
set(dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
|
function(_git_hash_main)
|
||||||
set(out "${dir}/git_hash.hh")
|
set(dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
|
||||||
|
set(out "${dir}/git_hash.hh")
|
||||||
|
|
||||||
find_program(SH sh REQUIRED)
|
find_program(BASH bash REQUIRED)
|
||||||
|
find_program(GIT git REQUIRED)
|
||||||
make_directory("${dir}")
|
|
||||||
add_custom_command(
|
make_directory("${dir}")
|
||||||
COMMAND ${SH} -c "echo constexpr const char\* GIT_HASH = \\\"`git rev-parse --short HEAD``git diff --quiet && echo \\\*`\\\"\\; > ${out}"
|
add_custom_target(git_hash_generate
|
||||||
OUTPUT "${out}"
|
COMMAND ${BASH} -c "echo constexpr const char\* GIT_HASH = \\\"$(${GIT} rev-parse --short HEAD)$([[ -z $(${GIT} status -s) ]] || echo \\\*)\\\"\\; > ${out}.temp"
|
||||||
DEPENDS "${PROJECT_SOURCE_DIR}/.git/HEAD"
|
COMMAND ${BASH} -c "diff '${out}.temp' '${out}' > /dev/null || mv '${out}.temp' '${out}'"
|
||||||
VERBATIM
|
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
|
||||||
)
|
VERBATIM
|
||||||
|
)
|
||||||
add_library(git_hash INTERFACE)
|
|
||||||
target_sources(git_hash PUBLIC "${out}")
|
add_library(git_hash INTERFACE)
|
||||||
target_include_directories(git_hash INTERFACE ${CMAKE_CURRENT_BINARY_DIR})
|
add_dependencies(git_hash git_hash_generate)
|
||||||
|
target_sources(git_hash PUBLIC "${out}")
|
||||||
unset(out)
|
target_include_directories(git_hash INTERFACE ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
unset(dir)
|
endfunction()
|
||||||
|
_git_hash_main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user