diff options
author | Brad King <brad.king@kitware.com> | 2024-03-14 15:43:46 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2024-03-14 15:44:00 (GMT) |
commit | d93a7c18d86af65076e092c6879991e6b29ae4be (patch) | |
tree | 44ea8cde4b2885e39e3fde5ff2e2001ad1347407 | |
parent | 886333da388c6c66d3073d73665118c55f693eaf (diff) | |
parent | 2b68048bdb63903eacd6f61e862654cadfc40b47 (diff) | |
download | CMake-d93a7c18d86af65076e092c6879991e6b29ae4be.zip CMake-d93a7c18d86af65076e092c6879991e6b29ae4be.tar.gz CMake-d93a7c18d86af65076e092c6879991e6b29ae4be.tar.bz2 |
Merge topic 'fc-MakeAvailable-leak-var' into release-3.29
2b68048bdb FetchContent: Don't leak temporary variable and restore var robustly
Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !9338
-rw-r--r-- | Modules/FetchContent.cmake | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/Modules/FetchContent.cmake b/Modules/FetchContent.cmake index 48cdaf4..fae51cf 100644 --- a/Modules/FetchContent.cmake +++ b/Modules/FetchContent.cmake @@ -1966,7 +1966,12 @@ macro(FetchContent_MakeAvailable) "${__cmake_contentName}" ) - list(APPEND __cmake_fcCurrentVarsStack "__fcprefix__${CMAKE_EXPORT_FIND_PACKAGE_NAME}") + if(DEFINED CMAKE_EXPORT_FIND_PACKAGE_NAME) + list(APPEND __cmake_fcCurrentVarsStack "${CMAKE_EXPORT_FIND_PACKAGE_NAME}") + else() + # This just needs to be something that can't be a real package name + list(APPEND __cmake_fcCurrentVarsStack "<<::VAR_NOT_SET::>>") + endif() set(CMAKE_EXPORT_FIND_PACKAGE_NAME "${__cmake_contentName}") # It's still valid if there are no saved details. The project may have @@ -2014,7 +2019,11 @@ macro(FetchContent_MakeAvailable) list(POP_BACK __cmake_fcCurrentVarsStack __cmake_contentNameLower __cmake_contentName + CMAKE_EXPORT_FIND_PACKAGE_NAME ) + if(CMAKE_EXPORT_FIND_PACKAGE_NAME STREQUAL "<<::VAR_NOT_SET::>>") + unset(CMAKE_EXPORT_FIND_PACKAGE_NAME) + endif() unset(__cmake_fcProvider_${__cmake_contentNameLower}) unset(__cmake_providerArgs) @@ -2023,12 +2032,6 @@ macro(FetchContent_MakeAvailable) unset(__cmake_item) unset(__cmake_contentDetails) - list(POP_BACK __cmake_fcCurrentVarsStack __cmake_original_export_find_package_name) - string(SUBSTRING "${__cmake_original_export_find_package_name}" - 12 -1 __cmake_original_export_find_package_name - ) - set(CMAKE_EXPORT_FIND_PACKAGE_NAME ${__cmake_original_export_find_package_name}) - FetchContent_GetProperties(${__cmake_contentName}) if(${__cmake_contentNameLower}_POPULATED) continue() @@ -2098,7 +2101,12 @@ macro(FetchContent_MakeAvailable) endif() if(EXISTS ${__cmake_srcdir}/CMakeLists.txt) - list(APPEND __cmake_fcCurrentVarsStack "__fcprefix__${CMAKE_EXPORT_FIND_PACKAGE_NAME}") + if(DEFINED CMAKE_EXPORT_FIND_PACKAGE_NAME) + list(APPEND __cmake_fcCurrentVarsStack "${CMAKE_EXPORT_FIND_PACKAGE_NAME}") + else() + # This just needs to be something that can't be a real package name + list(APPEND __cmake_fcCurrentVarsStack "<<::VAR_NOT_SET::>>") + endif() set(CMAKE_EXPORT_FIND_PACKAGE_NAME "${__cmake_contentName}") set(__cmake_add_subdirectory_args ${__cmake_srcdir} ${${__cmake_contentNameLower}_BINARY_DIR}) @@ -2110,11 +2118,10 @@ macro(FetchContent_MakeAvailable) endif() add_subdirectory(${__cmake_add_subdirectory_args}) - list(POP_BACK __cmake_fcCurrentVarsStack __cmake_original_export_find_package_name) - string(SUBSTRING "${__cmake_original_export_find_package_name}" - 12 -1 __cmake_original_export_find_package_name - ) - set(CMAKE_EXPORT_FIND_PACKAGE_NAME ${__cmake_original_export_find_package_name}) + list(POP_BACK __cmake_fcCurrentVarsStack CMAKE_EXPORT_FIND_PACKAGE_NAME) + if(CMAKE_EXPORT_FIND_PACKAGE_NAME STREQUAL "<<::VAR_NOT_SET::>>") + unset(CMAKE_EXPORT_FIND_PACKAGE_NAME) + endif() endif() unset(__cmake_srcdir) |