FindGit¶
Finds the Git distributed version control system.
Imported Targets¶
This module provides the following Imported Targets when the
CMAKE_ROLE
is PROJECT
:
Git::Git
在 3.14 版被加入.
Target that encapsulates Git command-line client executable. It can be used in
generator expressions
, and commands likeadd_custom_target()
andadd_custom_command()
. This target is available only if Git is found.
結果變數¶
This module defines the following variables:
Git_FOUND
Boolean indicating whether the Git was found. For backward compatibility, the
GIT_FOUND
variable is also set to the same value.GIT_VERSION_STRING
The version of Git found.
快取變數¶
The following cache variables may also be set:
GIT_EXECUTABLE
Path to the
git
command-line client executable.
範例¶
Finding Git and retrieving the latest commit from the project repository:
find_package(Git)
if(Git_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} --no-pager log -n 1 HEAD "--pretty=format:%h %s"
OUTPUT_VARIABLE output
RESULT_VARIABLE result
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(result EQUAL 0)
message(STATUS "Last Git commit: ${output}")
endif()
endif()