Use only Git commands in git_info
This commit is contained in:
parent
cefc2112e2
commit
45a4a0022f
@ -5,22 +5,66 @@
|
|||||||
# Git repository version and status information
|
# Git repository version and status information
|
||||||
# to the program output.
|
# to the program output.
|
||||||
#
|
#
|
||||||
# autocmake.cfg configuration::
|
# autocmake.yml configuration::
|
||||||
#
|
#
|
||||||
# fetch: https://github.com/scisoft/autocmake/raw/master/modules/git_info/git_info_sub.cmake
|
# url_root: https://github.com/coderefinery/autocmake/raw/master/
|
||||||
# https://github.com/scisoft/autocmake/raw/master/modules/git_info/git_info.h.in
|
# fetch:
|
||||||
|
# - "%(url_root)modules/git_info/git_info_sub.cmake"
|
||||||
|
# - "%(url_root)modules/git_info/git_info.h.in"
|
||||||
|
|
||||||
# CMAKE_CURRENT_LIST_DIR is undefined in CMake 2.8.2
|
# _header_location: where the Git info header file should be generated
|
||||||
# see https://public.kitware.com/Bug/print_bug_page.php?bug_id=11675
|
# _header_name: the Git info header name, complete with extension (.h, .hpp, .hxx or whatever)
|
||||||
# workaround: create CMAKE_CURRENT_LIST_DIR
|
function(generate_git_info_header _header_location _header_name)
|
||||||
get_filename_component(CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
|
find_package(Git)
|
||||||
add_custom_command(
|
|
||||||
OUTPUT ${PROJECT_BINARY_DIR}/git_info.h
|
set(_git_last_commit_hash "unknown")
|
||||||
COMMAND ${CMAKE_COMMAND} -D_target_dir=${PROJECT_BINARY_DIR} -P git_info_sub.cmake
|
set(_git_last_commit_author "unknown")
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
set(_git_last_commit_date "unknown")
|
||||||
|
set(_git_branch "unknown")
|
||||||
|
|
||||||
|
if(GIT_FOUND)
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${GIT_EXECUTABLE} --no-pager show -s --pretty=format:%h -n 1
|
||||||
|
OUTPUT_VARIABLE _git_last_commit_hash
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
ERROR_QUIET
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_target(
|
execute_process(
|
||||||
|
COMMAND ${GIT_EXECUTABLE} --no-pager show -s --pretty=format:%aN -n 1
|
||||||
|
OUTPUT_VARIABLE _git_last_commit_author
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
ERROR_QUIET
|
||||||
|
)
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${GIT_EXECUTABLE} --no-pager show -s --pretty=format:%ad -n 1
|
||||||
|
OUTPUT_VARIABLE _git_last_commit_date
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
ERROR_QUIET
|
||||||
|
)
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
|
||||||
|
OUTPUT_VARIABLE _git_branch
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
ERROR_QUIET
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
configure_file(
|
||||||
|
${PROJECT_SOURCE_DIR}/cmake/downloaded/git_info.h.in
|
||||||
|
${_header_location}/${_header_name}
|
||||||
|
@ONLY
|
||||||
|
)
|
||||||
|
|
||||||
|
unset(_git_last_commit_hash)
|
||||||
|
unset(_git_last_commit_author)
|
||||||
|
unset(_git_last_commit_date)
|
||||||
|
unset(_git_branch)
|
||||||
|
|
||||||
|
add_custom_target(
|
||||||
git_info
|
git_info
|
||||||
ALL DEPENDS ${PROJECT_BINARY_DIR}/git_info.h
|
ALL DEPENDS ${_header_location}/${_header_name}
|
||||||
)
|
)
|
||||||
|
endfunction()
|
||||||
|
@ -1,64 +0,0 @@
|
|||||||
#.rst:
|
|
||||||
#
|
|
||||||
# Creates git_info.h in the build directory.
|
|
||||||
# This file can be included in sources to print
|
|
||||||
# Git status information to the program output
|
|
||||||
# for reproducibility reasons.
|
|
||||||
|
|
||||||
find_package(Git)
|
|
||||||
|
|
||||||
set(_git_last_commit_hash "unknown")
|
|
||||||
set(_git_last_commit_author "unknown")
|
|
||||||
set(_git_last_commit_date "unknown")
|
|
||||||
set(_git_branch "unknown")
|
|
||||||
|
|
||||||
if(GIT_FOUND)
|
|
||||||
execute_process(
|
|
||||||
COMMAND ${GIT_EXECUTABLE} rev-list --max-count=1 --abbrev-commit HEAD
|
|
||||||
OUTPUT_VARIABLE _git_last_commit_hash
|
|
||||||
ERROR_QUIET
|
|
||||||
)
|
|
||||||
|
|
||||||
if(_git_last_commit_hash)
|
|
||||||
string(STRIP ${_git_last_commit_hash} _git_last_commit_hash)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
execute_process(
|
|
||||||
COMMAND ${GIT_EXECUTABLE} log --max-count=1 HEAD
|
|
||||||
OUTPUT_VARIABLE _git_last_commit
|
|
||||||
ERROR_QUIET
|
|
||||||
)
|
|
||||||
|
|
||||||
if(_git_last_commit)
|
|
||||||
string(REGEX MATCH "Author: +(.+) <.*@" temp "${_git_last_commit}")
|
|
||||||
set(_git_last_commit_author ${CMAKE_MATCH_1})
|
|
||||||
string(STRIP ${_git_last_commit_author} _git_last_commit_author)
|
|
||||||
string(REGEX MATCH "Date: +(.+[0-9][0-9][0-9][0-9] [+-][0-9][0-9][0-9][0-9])" temp "${_git_last_commit}")
|
|
||||||
set(_git_last_commit_date ${CMAKE_MATCH_1})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
execute_process(
|
|
||||||
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
|
|
||||||
OUTPUT_VARIABLE _git_branch
|
|
||||||
ERROR_QUIET
|
|
||||||
)
|
|
||||||
|
|
||||||
if(_git_branch)
|
|
||||||
string(STRIP ${_git_branch} _git_branch)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# CMAKE_CURRENT_LIST_DIR is undefined in CMake 2.8.2
|
|
||||||
# see https://public.kitware.com/Bug/print_bug_page.php?bug_id=11675
|
|
||||||
# workaround: create CMAKE_CURRENT_LIST_DIR
|
|
||||||
get_filename_component(CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
|
|
||||||
configure_file(
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/git_info.h.in
|
|
||||||
${_target_dir}/git_info.h
|
|
||||||
@ONLY
|
|
||||||
)
|
|
||||||
|
|
||||||
unset(_git_last_commit_hash)
|
|
||||||
unset(_git_last_commit_author)
|
|
||||||
unset(_git_last_commit_date)
|
|
||||||
unset(_git_branch)
|
|
Loading…
x
Reference in New Issue
Block a user