summaryrefslogtreecommitdiff
path: root/Modules/FetchContent.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-06-11 10:13:51 +0000
committerKitware Robot <kwrobot@kitware.com>2022-06-11 06:13:57 -0400
commit012eb492635cded21f8cb2bd6c37a856e5558cde (patch)
tree45d7cdf1a8375795bc50a2c1bce532c8d27658b1 /Modules/FetchContent.cmake
parentf0ebdce4e8f3400e9ecec698506ddf03ca4e053e (diff)
parentf19b48e0b89d5854e4a7a8fbbccadb38c02dcd76 (diff)
downloadcmake-012eb492635cded21f8cb2bd6c37a856e5558cde.tar.gz
Merge topic 'fetchcontent-global-targets' into release-3.24
f19b48e0b8 FetchContent: Honor CMAKE_FIND_PACKAGE_TARGETS_GLOBAL 1305bade56 Help: Add missing version directive for find_package() GLOBAL keyword Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !7347
Diffstat (limited to 'Modules/FetchContent.cmake')
-rw-r--r--Modules/FetchContent.cmake26
1 files changed, 24 insertions, 2 deletions
diff --git a/Modules/FetchContent.cmake b/Modules/FetchContent.cmake
index 75a161a1ea..d0a90f4deb 100644
--- a/Modules/FetchContent.cmake
+++ b/Modules/FetchContent.cmake
@@ -195,7 +195,14 @@ Commands
Everything after the ``FIND_PACKAGE_ARGS`` keyword is appended to the
:command:`find_package` call, so all other ``<contentOptions>`` must
- come before the ``FIND_PACKAGE_ARGS`` keyword.
+ come before the ``FIND_PACKAGE_ARGS`` keyword. If the
+ :variable:`CMAKE_FIND_PACKAGE_TARGETS_GLOBAL` variable is set to true
+ at the time ``FetchContent_Declare()`` is called, a ``GLOBAL`` keyword
+ will be appended to the :command:`find_package` arguments if it was
+ not already specified. It will also be appended if
+ ``FIND_PACKAGE_ARGS`` was not given, but
+ :variable:`FETCHCONTENT_TRY_FIND_PACKAGE_MODE` was set to ``ALWAYS``.
+
``OVERRIDE_FIND_PACKAGE`` cannot be used when ``FIND_PACKAGE_ARGS`` is
given.
@@ -260,6 +267,11 @@ Commands
The value of the :variable:`FETCHCONTENT_TRY_FIND_PACKAGE_MODE` variable
at the time :command:`FetchContent_Declare` was called determines whether
``FetchContent_MakeAvailable()`` can call :command:`find_package`.
+ If the :variable:`CMAKE_FIND_PACKAGE_TARGETS_GLOBAL` variable is set to
+ true when ``FetchContent_MakeAvailable()`` is called, it still affects
+ any imported targets created when that in turn calls
+ :command:`find_package`, even if that variable was false when the
+ corresponding details were declared.
If the dependency was not satisfied by a provider or a
:command:`find_package` call, ``FetchContent_MakeAvailable()`` then uses
@@ -1078,10 +1090,17 @@ function(__FetchContent_declareDetails contentName)
set(__cmdArgs)
set(__findPackageArgs)
+ set(__sawQuietKeyword NO)
+ set(__sawGlobalKeyword NO)
foreach(__item IN LISTS ARGN)
if(DEFINED __findPackageArgs)
# All remaining args are for find_package()
string(APPEND __findPackageArgs " [==[${__item}]==]")
+ if(__item STREQUAL "QUIET")
+ set(__sawQuietKeyword YES)
+ elseif(__item STREQUAL "GLOBAL")
+ set(__sawGlobalKeyword YES)
+ endif()
continue()
endif()
@@ -1120,9 +1139,12 @@ function(__FetchContent_declareDetails contentName)
if(__tryFindPackage AND __tryFindPackageAllowed)
set(propertyName "_FetchContent_${contentNameLower}_find_package_args")
define_property(GLOBAL PROPERTY ${propertyName})
- if(NOT QUIET IN_LIST __findPackageArgs)
+ if(NOT __sawQuietKeyword)
list(INSERT __findPackageArgs 0 QUIET)
endif()
+ if(CMAKE_FIND_PACKAGE_TARGETS_GLOBAL AND NOT __sawGlobalKeyword)
+ list(APPEND __findPackageArgs GLOBAL)
+ endif()
cmake_language(EVAL CODE
"set_property(GLOBAL PROPERTY ${propertyName} ${__findPackageArgs})"
)