mirror of
https://github.com/Kitware/CMake.git
synced 2026-03-16 23:41:15 -05:00
FindGit: Cache the version more effectively
In 315a200f0c (FindGit: Cache the GIT_EXECUTABLE version for the
current run, 2021-01-20), the GIT_VERSION_STRING was meant to be
cached after the first time it was computed for a given GIT_EXECUTABLE
location. That logic assumed GIT_VERSION_STRING would be visible in
the current scope, but it might not be. The global property alone is
enough to check whether the version has been determined previously,
so don't switch the logic based on whether GIT_VERSION_STRING is
defined or not.
Relates: #21703
This commit is contained in:
@@ -80,26 +80,26 @@ if(GIT_EXECUTABLE)
|
|||||||
# Avoid querying the version if we've already done that this run. For
|
# Avoid querying the version if we've already done that this run. For
|
||||||
# projects that use things like ExternalProject or FetchContent heavily,
|
# projects that use things like ExternalProject or FetchContent heavily,
|
||||||
# this saving can be measurable on some platforms.
|
# this saving can be measurable on some platforms.
|
||||||
set(__doGitVersionCheck YES)
|
#
|
||||||
if(DEFINED GIT_VERSION_STRING)
|
# This is an internal property, projects must not try to use it.
|
||||||
# This is an internal property, projects must not try to use it.
|
# We don't want this stored in the cache because it might still change
|
||||||
# We don't want this stored in the cache because it might still change
|
# between CMake runs, but it shouldn't change during a run for a given
|
||||||
# between CMake runs, but it shouldn't change during a run.
|
# git executable location.
|
||||||
get_property(__gitVersionProp GLOBAL
|
set(__doGitVersionCheck TRUE)
|
||||||
PROPERTY _CMAKE_FindGit_GIT_EXECUTABLE_VERSION
|
get_property(__gitVersionProp GLOBAL
|
||||||
)
|
PROPERTY _CMAKE_FindGit_GIT_EXECUTABLE_VERSION
|
||||||
if(__gitVersionProp)
|
)
|
||||||
list(GET __gitVersionProp 0 __gitExe)
|
if(__gitVersionProp)
|
||||||
list(GET __gitVersionProp 1 __gitVersion)
|
list(GET __gitVersionProp 0 __gitExe)
|
||||||
if("${__gitExe}" STREQUAL "${GIT_EXECUTABLE}" AND
|
list(GET __gitVersionProp 1 __gitVersion)
|
||||||
"${__gitVersion}" STREQUAL "${GIT_VERSION_STRING}")
|
if(__gitExe STREQUAL GIT_EXECUTABLE AND NOT __gitVersion STREQUAL "")
|
||||||
set(__doGitVersionCheck NO)
|
set(GIT_VERSION_STRING "${__gitVersion}")
|
||||||
endif()
|
set(__doGitVersionCheck FALSE)
|
||||||
endif()
|
endif()
|
||||||
unset(__gitVersionProp)
|
|
||||||
unset(__gitExe)
|
unset(__gitExe)
|
||||||
unset(__gitVersion)
|
unset(__gitVersion)
|
||||||
endif()
|
endif()
|
||||||
|
unset(__gitVersionProp)
|
||||||
|
|
||||||
if(__doGitVersionCheck)
|
if(__doGitVersionCheck)
|
||||||
execute_process(COMMAND ${GIT_EXECUTABLE} --version
|
execute_process(COMMAND ${GIT_EXECUTABLE} --version
|
||||||
@@ -121,6 +121,7 @@ if(GIT_EXECUTABLE)
|
|||||||
add_executable(Git::Git IMPORTED)
|
add_executable(Git::Git IMPORTED)
|
||||||
set_property(TARGET Git::Git PROPERTY IMPORTED_LOCATION "${GIT_EXECUTABLE}")
|
set_property(TARGET Git::Git PROPERTY IMPORTED_LOCATION "${GIT_EXECUTABLE}")
|
||||||
endif()
|
endif()
|
||||||
|
unset(_findgit_role)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
|
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
|
||||||
|
|||||||
Reference in New Issue
Block a user