summaryrefslogtreecommitdiff
path: root/Modules/FetchContent.cmake
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@crascit.com>2022-09-11 17:54:57 +1000
committerCraig Scott <craig.scott@crascit.com>2022-09-11 18:36:31 +1000
commit48b380c9613318b888473aa6f178d06de3f21e7e (patch)
tree181a1a2b988db2152ab087fedb8c5d9fa0907207 /Modules/FetchContent.cmake
parenta2f9e674bb15d91af15cec815a5c40c0ecc2ee9f (diff)
downloadcmake-48b380c9613318b888473aa6f178d06de3f21e7e.tar.gz
FetchContent: Ignore EXACT for redirected find_package() calls
When FetchContent_MakeAvailable() populates a dependency for which find_package() integration is enabled, all future calls to find_package() MUST succeed using the contents of the redirection directory. The generated config version file was not handling calls where the EXACT keyword was given, resulting in such calls rejecting the redirection directory's contents and continuing its search. It is not allowed to do that. Fix the generated file to also set PACKAGE_VERSION_EXACT to true so that calls with EXACT now accept it, as was originally intended. Fixes: #23950
Diffstat (limited to 'Modules/FetchContent.cmake')
-rw-r--r--Modules/FetchContent.cmake9
1 files changed, 6 insertions, 3 deletions
diff --git a/Modules/FetchContent.cmake b/Modules/FetchContent.cmake
index 20f0bd2a59..09a1512437 100644
--- a/Modules/FetchContent.cmake
+++ b/Modules/FetchContent.cmake
@@ -303,13 +303,16 @@ Commands
``<lowercaseName>-extra.cmake`` or ``<name>Extra.cmake`` file with the
``OPTIONAL`` flag (so the files can be missing and won't generate a
warning). Similarly, if no config version file exists, a very simple
- one will be written which sets ``PACKAGE_VERSION_COMPATIBLE`` to true.
+ one will be written which sets ``PACKAGE_VERSION_COMPATIBLE`` and
+ ``PACKAGE_VERSION_EXACT`` to true. This ensures all future calls to
+ :command:`find_package()` for the dependency will use the redirected
+ config file, regardless of any version requirements.
CMake cannot automatically determine an arbitrary dependency's version,
- so it cannot set ``PACKAGE_VERSION`` or ``PACKAGE_VERSION_EXACT``.
+ so it cannot set ``PACKAGE_VERSION``.
When a dependency is pulled in via :command:`add_subdirectory` in the
next step, it may choose to overwrite the generated config version file
in :variable:`CMAKE_FIND_PACKAGE_REDIRECTS_DIR` with one that also sets
- ``PACKAGE_VERSION``, and if appropriate, ``PACKAGE_VERSION_EXACT``.
+ ``PACKAGE_VERSION``.
The dependency may also write a ``<lowercaseName>-extra.cmake`` or
``<name>Extra.cmake`` file to perform custom processing or define any
variables that their normal (installed) package config file would