diff options
author | Brad King <brad.king@kitware.com> | 2022-09-12 13:37:59 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2022-09-12 13:38:06 (GMT) |
commit | ef756578512557443cd2854adcd6438643e06e80 (patch) | |
tree | ffd0d5654e5158a64894ca1d28519813e81bd432 | |
parent | 20f36aae147dc2fe16d0634df2be4cb2c4c40f62 (diff) | |
parent | 48b380c9613318b888473aa6f178d06de3f21e7e (diff) | |
download | CMake-ef756578512557443cd2854adcd6438643e06e80.zip CMake-ef756578512557443cd2854adcd6438643e06e80.tar.gz CMake-ef756578512557443cd2854adcd6438643e06e80.tar.bz2 |
Merge topic 'fetchcontent-redirect-version-exact' into release-3.24
48b380c961 FetchContent: Ignore EXACT for redirected find_package() calls
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !7665
-rw-r--r-- | Modules/FetchContent.cmake | 9 | ||||
-rw-r--r-- | Modules/FetchContent/package-config-version.cmake.in | 5 | ||||
-rw-r--r-- | Tests/RunCMake/FetchContent_find_package/PreferFetchContent.cmake | 4 |
3 files changed, 14 insertions, 4 deletions
diff --git a/Modules/FetchContent.cmake b/Modules/FetchContent.cmake index bb7e44d..995e69a 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 diff --git a/Modules/FetchContent/package-config-version.cmake.in b/Modules/FetchContent/package-config-version.cmake.in index 7f19094..9fcade7 100644 --- a/Modules/FetchContent/package-config-version.cmake.in +++ b/Modules/FetchContent/package-config-version.cmake.in @@ -1,5 +1,8 @@ # Automatically generated by CMake's FetchContent module. # Do not edit this file, it will be regenerated every time CMake runs. -# Version not available, assuming it is compatible +# Version not available, assuming it is compatible. We must also say it is an +# exact match to ensure find_package() calls with the EXACT keyword still get +# redirected. set(PACKAGE_VERSION_COMPATIBLE TRUE) +set(PACKAGE_VERSION_EXACT TRUE) diff --git a/Tests/RunCMake/FetchContent_find_package/PreferFetchContent.cmake b/Tests/RunCMake/FetchContent_find_package/PreferFetchContent.cmake index c1030fb..4943f9e 100644 --- a/Tests/RunCMake/FetchContent_find_package/PreferFetchContent.cmake +++ b/Tests/RunCMake/FetchContent_find_package/PreferFetchContent.cmake @@ -18,3 +18,7 @@ message(STATUS "Lowercase extra file was read") # This is expected to be re-routed to a FetchContent_MakeAvailable() call find_package(AddedProject REQUIRED) + +# Verify that find_package() version constraints are fully ignored by the +# default-generated config version file +find_package(AddedProject 1.2.3 EXACT REQUIRED) |