4 # checks the current source directory for the presence of
9 # git_check_repository(GIT_REPO_FOUND)
11 function(git_check_repository found)
12 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
13 set(${found} TRUE PARENT_SCOPE)
15 set(${found} FALSE PARENT_SCOPE)
19 # get commit hash of HEAD
21 # This function assumes to have a git repository present.
25 # git_commit_hash(GIT_HASH)
27 # an optional second argument is supported, which returns
28 # the short version of the hash:
30 # git_commit_hash(GIT_HASH GIT_HASH_SHORT)
32 function(git_commit_hash hash)
34 message(FATAL "too many arugments for `git_commit_hash`")
39 COMMAND ${GIT_EXECUTABLE} log -1 --format=format:%H HEAD
40 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
41 OUTPUT_VARIABLE commit_hash
42 OUTPUT_STRIP_TRAILING_WHITESPACE
44 set(${hash} ${commit_hash} PARENT_SCOPE)
47 string(SUBSTRING "${commit_hash}" 0 7 commit_hash_short)
48 set(${ARGV1} ${commit_hash_short} PARENT_SCOPE)
54 # This function assumes to have a git repository present.
58 # git_branch_name(GIT_BRANCH)
60 function(git_branch_name branch_name)
62 COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
63 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
64 OUTPUT_VARIABLE branch
65 OUTPUT_STRIP_TRAILING_WHITESPACE
67 set(${branch_name} ${branch} PARENT_SCOPE)
70 # generate list of authors
72 # This function assumes to have a git repository present.
76 # git_authtors(GIT_AUTHOS)
78 # function is able to return a nice bullet point list also.
79 # pass a second argument to the function:
81 # git_authors(AUTHORS AUTHORS_LIST)
83 function(git_authors authors)
85 message(FATAL "too many arugments for `git_authors`")
89 COMMAND ${GIT_EXECUTABLE} log --format=%an
90 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
91 OUTPUT_VARIABLE GIT_AUTHORS
92 OUTPUT_STRIP_TRAILING_WHITESPACE
94 string(REPLACE "\n" ";" GIT_AUTHORS "${GIT_AUTHORS}")
95 list(SORT GIT_AUTHORS)
96 list(REMOVE_DUPLICATES GIT_AUTHORS)
97 set(${authors} ${GIT_AUTHORS} PARENT_SCOPE)
100 set(GIT_AUTHORS_LIST "")
101 foreach(AUTHOR ${GIT_AUTHORS})
102 string(CONCAT GIT_AUTHORS_LIST ${GIT_AUTHORS_LIST} "- ${AUTHOR}\n")
104 set(${ARGV1} ${GIT_AUTHORS_LIST} PARENT_SCOPE)
108 # returns the tag that points at HEAD, empty if none
114 function(git_head_tag tag)
116 COMMAND ${GIT_EXECUTABLE} tag --points-at HEAD
117 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
118 OUTPUT_VARIABLE head_tag
119 OUTPUT_STRIP_TRAILING_WHITESPACE
121 set(${tag} ${head_tag} PARENT_SCOPE)