mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Properly persist git hash on each build (#1391)
Properly persist git hash on each build Rebuild `git_hash.h` only when `.git` folder changes `add_custom_target()` always considers its target out-of-date which leads to rebuilding of `git_hash.h` on every build (which is ironically what we wanted) and consequently rebuilding of build_options.c and relinking of c3c even when no changes are made, which is mildly annoying. We are replacing `add_custom_target()` with `add_custom_command()` which depends on `.git`, so `git_hash.h` is only rebuilt if any git commands are performed. Which is less annoying. In case of no `.git` we simply do not depend on it which leads to `git_hash.h` being rebuilt only once.
This commit is contained in:
14
git_hash.cmake
Normal file
14
git_hash.cmake
Normal file
@@ -0,0 +1,14 @@
|
||||
find_package(Git QUIET)
|
||||
|
||||
set(GIT_HASH "unknown")
|
||||
|
||||
if(GIT_FOUND AND EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git")
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
|
||||
OUTPUT_VARIABLE GIT_HASH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
COMMAND_ERROR_IS_FATAL ANY)
|
||||
endif()
|
||||
|
||||
message("Git Hash: ${GIT_HASH}")
|
||||
|
||||
file(WRITE ${CMAKE_BINARY_DIR}/git_hash.h "#pragma once\n#define GIT_HASH \"${GIT_HASH}\"\n")
|
||||
Reference in New Issue
Block a user