summaryrefslogtreecommitdiffstats
path: root/Modules/FetchContent.cmake
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@crascit.com>2021-01-19 23:15:45 (GMT)
committerCraig Scott <craig.scott@crascit.com>2021-01-19 23:16:21 (GMT)
commit315a200f0c45415e8ab0da058aab9bbfa39c3c05 (patch)
tree6feb6f39b8dacadc4a6509c0404f48a2f7d1c4cc /Modules/FetchContent.cmake
parentddd9545895326e45bee798ae0b5a5d2bf8dae239 (diff)
downloadCMake-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/FetchContent.cmake')
-rw-r--r--Modules/FetchContent.cmake16
1 files changed, 16 insertions, 0 deletions
diff --git a/Modules/FetchContent.cmake b/Modules/FetchContent.cmake
index ba2acfc..8adef47 100644
--- a/Modules/FetchContent.cmake
+++ b/Modules/FetchContent.cmake
@@ -964,6 +964,22 @@ ExternalProject_Add_Step(${contentName}-populate copyfile
"-DCMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY=${CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY}")
endif()
+ # Avoid using if(... IN_LIST ...) so we don't have to alter policy settings
+ set(__FETCHCONTENT_CACHED_INFO "")
+ list(FIND ARG_UNPARSED_ARGUMENTS GIT_REPOSITORY indexResult)
+ if(indexResult GREATER_EQUAL 0)
+ find_package(Git QUIET)
+ set(__FETCHCONTENT_CACHED_INFO
+"# Pass through things we've already detected in the main project to avoid
+# paying the cost of redetecting them again in ExternalProject_Add()
+set(GIT_EXECUTABLE [==[${GIT_EXECUTABLE}]==])
+set(GIT_VERSION_STRING [==[${GIT_VERSION_STRING}]==])
+set_property(GLOBAL PROPERTY _CMAKE_FindGit_GIT_EXECUTABLE_VERSION
+ [==[${GIT_EXECUTABLE};${GIT_VERSION_STRING}]==]
+)
+")
+ endif()
+
# Create and build a separate CMake project to carry out the population.
# If we've already previously done these steps, they will not cause
# anything to be updated, so extra rebuilds of the project won't occur.