summaryrefslogtreecommitdiff
path: root/Modules/FindGit.cmake
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@crascit.com>2021-02-05 21:41:57 +1100
committerCraig Scott <craig.scott@crascit.com>2021-02-05 21:45:00 +1100
commitc99dfd7be78c4e69a96b837b40f1a9b20bc2e277 (patch)
tree9fa65125e6611737f25a336c090ef844daa9cd28 /Modules/FindGit.cmake
parent36bb0e32d7e3976eed424078cf5cac459651f0f1 (diff)
downloadcmake-c99dfd7be78c4e69a96b837b40f1a9b20bc2e277.tar.gz
FindGit: Cache the version more effectively
In 315a200f0c4 (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
Diffstat (limited to 'Modules/FindGit.cmake')
-rw-r--r--Modules/FindGit.cmake33
1 files changed, 17 insertions, 16 deletions
diff --git a/Modules/FindGit.cmake b/Modules/FindGit.cmake
index 83da707b74..99850b4f17 100644
--- a/Modules/FindGit.cmake
+++ b/Modules/FindGit.cmake
@@ -80,26 +80,26 @@ if(GIT_EXECUTABLE)
# Avoid querying the version if we've already done that this run. For
# projects that use things like ExternalProject or FetchContent heavily,
# 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.
- # 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.
- get_property(__gitVersionProp GLOBAL
- PROPERTY _CMAKE_FindGit_GIT_EXECUTABLE_VERSION
- )
- if(__gitVersionProp)
- list(GET __gitVersionProp 0 __gitExe)
- list(GET __gitVersionProp 1 __gitVersion)
- if("${__gitExe}" STREQUAL "${GIT_EXECUTABLE}" AND
- "${__gitVersion}" STREQUAL "${GIT_VERSION_STRING}")
- set(__doGitVersionCheck NO)
- endif()
+ #
+ # 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
+ # between CMake runs, but it shouldn't change during a run for a given
+ # git executable location.
+ set(__doGitVersionCheck TRUE)
+ get_property(__gitVersionProp GLOBAL
+ PROPERTY _CMAKE_FindGit_GIT_EXECUTABLE_VERSION
+ )
+ if(__gitVersionProp)
+ list(GET __gitVersionProp 0 __gitExe)
+ list(GET __gitVersionProp 1 __gitVersion)
+ if(__gitExe STREQUAL GIT_EXECUTABLE AND NOT __gitVersion STREQUAL "")
+ set(GIT_VERSION_STRING "${__gitVersion}")
+ set(__doGitVersionCheck FALSE)
endif()
- unset(__gitVersionProp)
unset(__gitExe)
unset(__gitVersion)
endif()
+ unset(__gitVersionProp)
if(__doGitVersionCheck)
execute_process(COMMAND ${GIT_EXECUTABLE} --version
@@ -121,6 +121,7 @@ if(GIT_EXECUTABLE)
add_executable(Git::Git IMPORTED)
set_property(TARGET Git::Git PROPERTY IMPORTED_LOCATION "${GIT_EXECUTABLE}")
endif()
+ unset(_findgit_role)
endif()
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)