diff options
author | Craig Scott <craig.scott@crascit.com> | 2021-01-19 23:15:45 (GMT) |
---|---|---|
committer | Craig Scott <craig.scott@crascit.com> | 2021-01-19 23:16:21 (GMT) |
commit | 315a200f0c45415e8ab0da058aab9bbfa39c3c05 (patch) | |
tree | 6feb6f39b8dacadc4a6509c0404f48a2f7d1c4cc /Modules/ExternalProject.cmake | |
parent | ddd9545895326e45bee798ae0b5a5d2bf8dae239 (diff) | |
download | CMake-315a200f0c45415e8ab0da058aab9bbfa39c3c05.zip CMake-315a200f0c45415e8ab0da058aab9bbfa39c3c05.tar.gz CMake-315a200f0c45415e8ab0da058aab9bbfa39c3c05.tar.bz2 |
FindGit: Cache the GIT_EXECUTABLE version for the current run
The git version should not change while CMake is running. When
using FetchContent with many dependencies, the repeated calls
to get the git version every time ExternalProject is used can be
measurable on some platforms. This commit queries that version
only once and then caches it in a global property for the rest of that
run. The git version can still safely change between runs because it
is not cached, only the GIT_EXECUTABLE location is cached.
Relates: #21703
Diffstat (limited to 'Modules/ExternalProject.cmake')
-rw-r--r-- | Modules/ExternalProject.cmake | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake index 3307bc6..1e50c6d 100644 --- a/Modules/ExternalProject.cmake +++ b/Modules/ExternalProject.cmake @@ -2630,10 +2630,13 @@ function(_ep_add_download_command name) --non-interactive ${svn_trust_cert_args} ${svn_user_pw_args} ${src_name}) list(APPEND depends ${stamp_dir}/${name}-svninfo.txt) elseif(git_repository) - unset(CMAKE_MODULE_PATH) # Use CMake builtin find module - find_package(Git QUIET) - if(NOT GIT_EXECUTABLE) - message(FATAL_ERROR "error: could not find git for clone of ${name}") + # FetchContent gives us these directly, so don't try to recompute them + if(NOT GIT_EXECUTABLE OR NOT GIT_VERSION_STRING) + unset(CMAKE_MODULE_PATH) # Use CMake builtin find module + find_package(Git QUIET) + if(NOT GIT_EXECUTABLE) + message(FATAL_ERROR "error: could not find git for clone of ${name}") + endif() endif() _ep_get_git_submodules_recurse(git_submodules_recurse) @@ -2951,10 +2954,13 @@ function(_ep_add_update_command name) --non-interactive ${svn_trust_cert_args} ${svn_user_pw_args}) set(always 1) elseif(git_repository) - unset(CMAKE_MODULE_PATH) # Use CMake builtin find module - find_package(Git QUIET) - if(NOT GIT_EXECUTABLE) - message(FATAL_ERROR "error: could not find git for fetch of ${name}") + # FetchContent gives us these directly, so don't try to recompute them + if(NOT GIT_EXECUTABLE OR NOT GIT_VERSION_STRING) + unset(CMAKE_MODULE_PATH) # Use CMake builtin find module + find_package(Git QUIET) + if(NOT GIT_EXECUTABLE) + message(FATAL_ERROR "error: could not find git for fetch of ${name}") + endif() endif() set(work_dir ${source_dir}) set(comment "Performing update step for '${name}'") |