Files
CMake/Tests/RunCMake/FetchContent_find_package/PreferFetchContent.cmake
Craig Scott 48b380c961 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
2022-09-11 18:36:31 +10:00

25 lines
756 B
CMake

include(FetchContent)
FetchContent_Declare(
AddedProject
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/AddedProject
OVERRIDE_FIND_PACKAGE
)
# The default generated config package files are expected to include these when present
file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/AddedProjectExtra.cmake [[
message(STATUS "Uppercase extra file was read")
]]
)
file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/addedproject-extra.cmake [[
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)