mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-16 22:37:30 +08:00
FetchContent: Use private local variables in FetchContent_MakeAvailable
This commit is contained in:

committed by
Arcturus

parent
96011ab06d
commit
5d32ce320b
@@ -1182,11 +1182,11 @@ endfunction()
|
|||||||
# calls will be available to the caller.
|
# calls will be available to the caller.
|
||||||
macro(FetchContent_MakeAvailable)
|
macro(FetchContent_MakeAvailable)
|
||||||
|
|
||||||
foreach(contentName IN ITEMS ${ARGV})
|
foreach(__cmake_contentName IN ITEMS ${ARGV})
|
||||||
string(TOLOWER ${contentName} contentNameLower)
|
string(TOLOWER ${__cmake_contentName} __cmake_contentNameLower)
|
||||||
FetchContent_GetProperties(${contentName})
|
FetchContent_GetProperties(${__cmake_contentName})
|
||||||
if(NOT ${contentNameLower}_POPULATED)
|
if(NOT ${__cmake_contentNameLower}_POPULATED)
|
||||||
FetchContent_Populate(${contentName})
|
FetchContent_Populate(${__cmake_contentName})
|
||||||
|
|
||||||
# Only try to call add_subdirectory() if the populated content
|
# Only try to call add_subdirectory() if the populated content
|
||||||
# can be treated that way. Protecting the call with the check
|
# 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
|
# for ExternalProject. It won't matter if it was passed through
|
||||||
# to the ExternalProject sub-build, since it would have been
|
# to the ExternalProject sub-build, since it would have been
|
||||||
# ignored there.
|
# ignored there.
|
||||||
set(__fc_srcdir "${${contentNameLower}_SOURCE_DIR}")
|
set(__cmake_srcdir "${${__cmake_contentNameLower}_SOURCE_DIR}")
|
||||||
__FetchContent_getSavedDetails(${contentName} contentDetails)
|
__FetchContent_getSavedDetails(${__cmake_contentName} __cmake_contentDetails)
|
||||||
if("${contentDetails}" STREQUAL "")
|
if("${__cmake_contentDetails}" STREQUAL "")
|
||||||
message(FATAL_ERROR "No details have been set for content: ${contentName}")
|
message(FATAL_ERROR "No details have been set for content: ${__cmake_contentName}")
|
||||||
endif()
|
endif()
|
||||||
cmake_parse_arguments(__fc_arg "" "SOURCE_SUBDIR" "" ${contentDetails})
|
cmake_parse_arguments(__cmake_arg "" "SOURCE_SUBDIR" "" ${__cmake_contentDetails})
|
||||||
if(NOT "${__fc_arg_SOURCE_SUBDIR}" STREQUAL "")
|
if(NOT "${__cmake_arg_SOURCE_SUBDIR}" STREQUAL "")
|
||||||
string(APPEND __fc_srcdir "/${__fc_arg_SOURCE_SUBDIR}")
|
string(APPEND __cmake_srcdir "/${__cmake_arg_SOURCE_SUBDIR}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(EXISTS ${__fc_srcdir}/CMakeLists.txt)
|
if(EXISTS ${__cmake_srcdir}/CMakeLists.txt)
|
||||||
add_subdirectory(${__fc_srcdir} ${${contentNameLower}_BINARY_DIR})
|
add_subdirectory(${__cmake_srcdir} ${${__cmake_contentNameLower}_BINARY_DIR})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
unset(__fc_srcdir)
|
unset(__cmake_srcdir)
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
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()
|
endmacro()
|
||||||
|
Reference in New Issue
Block a user