summaryrefslogtreecommitdiffstats
path: root/Modules/FetchContent.cmake
diff options
context:
space:
mode:
authorArcturus Arcturus <arcturus98@outlook.com>2021-05-11 10:27:40 (GMT)
committerArcturus <arcturus98@outlook.com>2021-05-13 12:52:16 (GMT)
commit5d32ce320be5081d53a431126143360e364803be (patch)
tree55fb78f8e2be985000108d242687fd33c9a90122 /Modules/FetchContent.cmake
parent96011ab06d8839010c181d501c58c8e914f3ba91 (diff)
downloadCMake-5d32ce320be5081d53a431126143360e364803be.zip
CMake-5d32ce320be5081d53a431126143360e364803be.tar.gz
CMake-5d32ce320be5081d53a431126143360e364803be.tar.bz2
FetchContent: Use private local variables in FetchContent_MakeAvailable
Diffstat (limited to 'Modules/FetchContent.cmake')
-rw-r--r--Modules/FetchContent.cmake36
1 files changed, 21 insertions, 15 deletions
diff --git a/Modules/FetchContent.cmake b/Modules/FetchContent.cmake
index f5de930..bd82a90 100644
--- a/Modules/FetchContent.cmake
+++ b/Modules/FetchContent.cmake
@@ -1182,11 +1182,11 @@ endfunction()
# calls will be available to the caller.
macro(FetchContent_MakeAvailable)
- foreach(contentName IN ITEMS ${ARGV})
- string(TOLOWER ${contentName} contentNameLower)
- FetchContent_GetProperties(${contentName})
- if(NOT ${contentNameLower}_POPULATED)
- FetchContent_Populate(${contentName})
+ foreach(__cmake_contentName IN ITEMS ${ARGV})
+ string(TOLOWER ${__cmake_contentName} __cmake_contentNameLower)
+ FetchContent_GetProperties(${__cmake_contentName})
+ if(NOT ${__cmake_contentNameLower}_POPULATED)
+ FetchContent_Populate(${__cmake_contentName})
# Only try to call add_subdirectory() if the populated content
# can be treated that way. Protecting the call with the check
@@ -1197,22 +1197,28 @@ macro(FetchContent_MakeAvailable)
# for ExternalProject. It won't matter if it was passed through
# to the ExternalProject sub-build, since it would have been
# ignored there.
- set(__fc_srcdir "${${contentNameLower}_SOURCE_DIR}")
- __FetchContent_getSavedDetails(${contentName} contentDetails)
- if("${contentDetails}" STREQUAL "")
- message(FATAL_ERROR "No details have been set for content: ${contentName}")
+ set(__cmake_srcdir "${${__cmake_contentNameLower}_SOURCE_DIR}")
+ __FetchContent_getSavedDetails(${__cmake_contentName} __cmake_contentDetails)
+ if("${__cmake_contentDetails}" STREQUAL "")
+ message(FATAL_ERROR "No details have been set for content: ${__cmake_contentName}")
endif()
- cmake_parse_arguments(__fc_arg "" "SOURCE_SUBDIR" "" ${contentDetails})
- if(NOT "${__fc_arg_SOURCE_SUBDIR}" STREQUAL "")
- string(APPEND __fc_srcdir "/${__fc_arg_SOURCE_SUBDIR}")
+ cmake_parse_arguments(__cmake_arg "" "SOURCE_SUBDIR" "" ${__cmake_contentDetails})
+ if(NOT "${__cmake_arg_SOURCE_SUBDIR}" STREQUAL "")
+ string(APPEND __cmake_srcdir "/${__cmake_arg_SOURCE_SUBDIR}")
endif()
- if(EXISTS ${__fc_srcdir}/CMakeLists.txt)
- add_subdirectory(${__fc_srcdir} ${${contentNameLower}_BINARY_DIR})
+ if(EXISTS ${__cmake_srcdir}/CMakeLists.txt)
+ add_subdirectory(${__cmake_srcdir} ${${__cmake_contentNameLower}_BINARY_DIR})
endif()
- unset(__fc_srcdir)
+ unset(__cmake_srcdir)
endif()
endforeach()
+ # clear local variables to prevent leaking into the caller's scope
+ unset(__cmake_contentName)
+ unset(__cmake_contentNameLower)
+ unset(__cmake_contentDetails)
+ unset(__cmake_arg_SOURCE_SUBDIR)
+
endmacro()