diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2023-11-07 19:53:28 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2023-11-13 16:07:53 (GMT) |
commit | 0ad8fc5a63835e477b4d70b44ac34fab4aeb96dc (patch) | |
tree | 86729b6d7c4fe30fde8f5deada1d8da312fdab90 /Modules/FetchContent.cmake | |
parent | c6e6861e631ecfdc96c79f562a66021cb8971fcc (diff) | |
download | CMake-0ad8fc5a63835e477b4d70b44ac34fab4aeb96dc.zip CMake-0ad8fc5a63835e477b4d70b44ac34fab4aeb96dc.tar.gz CMake-0ad8fc5a63835e477b4d70b44ac34fab4aeb96dc.tar.bz2 |
FetchContent: Set CMAKE_EXPORT_FIND_PACKAGE_NAME
Diffstat (limited to 'Modules/FetchContent.cmake')
-rw-r--r-- | Modules/FetchContent.cmake | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Modules/FetchContent.cmake b/Modules/FetchContent.cmake index ad5a6f1..aa7f20a 100644 --- a/Modules/FetchContent.cmake +++ b/Modules/FetchContent.cmake @@ -373,6 +373,10 @@ Commands :command:`FetchContent_Declare`, the ``EXCLUDE_FROM_ALL`` keyword will be added to the :command:`add_subdirectory` command as well. + .. versionadded:: 3.29 + :variable:`CMAKE_EXPORT_FIND_PACKAGE_NAME` is set to the dependency name + before calling :command:`add_subdirectory`. + Projects should aim to declare the details of all dependencies they might use before they call ``FetchContent_MakeAvailable()`` for any of them. This ensures that if any of the dependencies are also sub-dependencies of @@ -1944,6 +1948,10 @@ macro(FetchContent_MakeAvailable) "Trying FETCHCONTENT_MAKEAVAILABLE_SERIAL dependency provider for " "${__cmake_contentName}" ) + + list(APPEND __cmake_fcCurrentVarsStack "__fcprefix__${CMAKE_EXPORT_FIND_PACKAGE_NAME}") + set(CMAKE_EXPORT_FIND_PACKAGE_NAME "${__cmake_contentName}") + # It's still valid if there are no saved details. The project may have # been written to assume a dependency provider is always set and will # provide dependencies without having any declared details for them. @@ -1998,6 +2006,12 @@ 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() @@ -2067,6 +2081,9 @@ macro(FetchContent_MakeAvailable) endif() if(EXISTS ${__cmake_srcdir}/CMakeLists.txt) + list(APPEND __cmake_fcCurrentVarsStack "__fcprefix__${CMAKE_EXPORT_FIND_PACKAGE_NAME}") + set(CMAKE_EXPORT_FIND_PACKAGE_NAME "${__cmake_contentName}") + set(__cmake_add_subdirectory_args ${__cmake_srcdir} ${${__cmake_contentNameLower}_BINARY_DIR}) if(__cmake_arg_EXCLUDE_FROM_ALL) list(APPEND __cmake_add_subdirectory_args EXCLUDE_FROM_ALL) @@ -2075,6 +2092,12 @@ macro(FetchContent_MakeAvailable) list(APPEND __cmake_add_subdirectory_args SYSTEM) 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}) endif() unset(__cmake_srcdir) |