summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/CMakeLists.txt1
-rw-r--r--Tests/RunCMake/FetchContent_find_package/AddedProject/CMakeLists.txt4
-rw-r--r--Tests/RunCMake/FetchContent_find_package/BadArgs_find_package-result.txt1
-rw-r--r--Tests/RunCMake/FetchContent_find_package/BadArgs_find_package-stderr.txt3
-rw-r--r--Tests/RunCMake/FetchContent_find_package/BadArgs_find_package.cmake9
-rw-r--r--Tests/RunCMake/FetchContent_find_package/CMAKE_FIND_PACKAGE_REDIRECTS_DIR-AlwaysEmptied-Setup.cmake3
-rw-r--r--Tests/RunCMake/FetchContent_find_package/CMAKE_FIND_PACKAGE_REDIRECTS_DIR-AlwaysEmptied.cmake9
-rw-r--r--Tests/RunCMake/FetchContent_find_package/CMAKE_FIND_PACKAGE_REDIRECTS_DIR-Exists.cmake18
-rw-r--r--Tests/RunCMake/FetchContent_find_package/CMakeLists.txt7
-rw-r--r--Tests/RunCMake/FetchContent_find_package/FatalIfAdded/CMakeLists.txt1
-rw-r--r--Tests/RunCMake/FetchContent_find_package/MissingDetails-result.txt1
-rw-r--r--Tests/RunCMake/FetchContent_find_package/MissingDetails-stderr.txt1
-rw-r--r--Tests/RunCMake/FetchContent_find_package/MissingDetails.cmake3
-rw-r--r--Tests/RunCMake/FetchContent_find_package/PackageConfigs/AddedProjectConfig.cmake2
-rw-r--r--Tests/RunCMake/FetchContent_find_package/PackageConfigs/FirstProjectConfig.cmake2
-rw-r--r--Tests/RunCMake/FetchContent_find_package/PackageConfigs/SecondProjectConfig.cmake1
-rw-r--r--Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindFirstProject.cmake1
-rw-r--r--Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindSecondProject.cmake1
-rw-r--r--Tests/RunCMake/FetchContent_find_package/PreferFetchContent-stdout.txt3
-rw-r--r--Tests/RunCMake/FetchContent_find_package/PreferFetchContent.cmake20
-rw-r--r--Tests/RunCMake/FetchContent_find_package/Prefer_find_package-stdout.txt3
-rw-r--r--Tests/RunCMake/FetchContent_find_package/Prefer_find_package.cmake15
-rw-r--r--Tests/RunCMake/FetchContent_find_package/PreserveEmptyArgs-stdout.txt4
-rw-r--r--Tests/RunCMake/FetchContent_find_package/PreserveEmptyArgs.cmake13
-rw-r--r--Tests/RunCMake/FetchContent_find_package/ProjectProvidesPackageConfigFiles-stdout.txt4
-rw-r--r--Tests/RunCMake/FetchContent_find_package/ProjectProvidesPackageConfigFiles.cmake40
-rw-r--r--Tests/RunCMake/FetchContent_find_package/Redirect_find_package_MODULE-stdout.txt9
-rw-r--r--Tests/RunCMake/FetchContent_find_package/Redirect_find_package_MODULE.cmake39
-rw-r--r--Tests/RunCMake/FetchContent_find_package/RunCMakeTest.cmake22
-rw-r--r--Tests/RunCMake/FetchContent_find_package/Try_find_package-ALWAYS-stdout.txt2
-rw-r--r--Tests/RunCMake/FetchContent_find_package/Try_find_package-ALWAYS.cmake18
-rw-r--r--Tests/RunCMake/FetchContent_find_package/Try_find_package-BOGUS-result.txt1
-rw-r--r--Tests/RunCMake/FetchContent_find_package/Try_find_package-BOGUS-stderr.txt2
-rw-r--r--Tests/RunCMake/FetchContent_find_package/Try_find_package-BOGUS.cmake8
-rw-r--r--Tests/RunCMake/FetchContent_find_package/Try_find_package-NEVER-stdout.txt1
-rw-r--r--Tests/RunCMake/FetchContent_find_package/Try_find_package-NEVER.cmake12
-rw-r--r--Tests/RunCMake/FetchContent_find_package/Try_find_package-OPT_IN-stdout.txt2
-rw-r--r--Tests/RunCMake/FetchContent_find_package/Try_find_package-OPT_IN.cmake20
-rw-r--r--Tests/RunCMake/find_package/FromPATHEnv-stderr.txt9
-rw-r--r--Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt9
-rw-r--r--Tests/RunCMake/find_package/ModuleModeDebugPkg-stderr.txt10
41 files changed, 334 insertions, 0 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index c2677a0..325ec2f 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -784,6 +784,7 @@ if(CMake_TEST_RunCMake_ExternalProject_DOWNLOAD_SERVER_TIMEOUT)
endif()
add_RunCMake_test(ExternalProject)
add_RunCMake_test(FetchContent)
+add_RunCMake_test(FetchContent_find_package)
set(CTestCommandLine_ARGS -DPython_EXECUTABLE=${Python_EXECUTABLE})
if(NOT CMake_TEST_EXTERNAL_CMAKE)
list(APPEND CTestCommandLine_ARGS -DTEST_AFFINITY=$<TARGET_FILE:testAffinity>)
diff --git a/Tests/RunCMake/FetchContent_find_package/AddedProject/CMakeLists.txt b/Tests/RunCMake/FetchContent_find_package/AddedProject/CMakeLists.txt
new file mode 100644
index 0000000..8be00ed
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/AddedProject/CMakeLists.txt
@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 3.13...3.23)
+project(AddedProject LANGUAGES NONE)
+
+message(STATUS "Confirmation project has been added")
diff --git a/Tests/RunCMake/FetchContent_find_package/BadArgs_find_package-result.txt b/Tests/RunCMake/FetchContent_find_package/BadArgs_find_package-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/BadArgs_find_package-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/FetchContent_find_package/BadArgs_find_package-stderr.txt b/Tests/RunCMake/FetchContent_find_package/BadArgs_find_package-stderr.txt
new file mode 100644
index 0000000..b6996b5
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/BadArgs_find_package-stderr.txt
@@ -0,0 +1,3 @@
+CMake Error at .*/FetchContent.cmake:[0-9]+ \(message\):
+ Cannot specify both OVERRIDE_FIND_PACKAGE and FIND_PACKAGE_ARGS when
+ declaring details for AddedProject
diff --git a/Tests/RunCMake/FetchContent_find_package/BadArgs_find_package.cmake b/Tests/RunCMake/FetchContent_find_package/BadArgs_find_package.cmake
new file mode 100644
index 0000000..c1272b4
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/BadArgs_find_package.cmake
@@ -0,0 +1,9 @@
+include(FetchContent)
+
+FetchContent_Declare(
+ AddedProject
+ SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/AddedProject
+ # The following two args are mutually exclusive
+ OVERRIDE_FIND_PACKAGE
+ FIND_PACKAGE_ARGS
+)
diff --git a/Tests/RunCMake/FetchContent_find_package/CMAKE_FIND_PACKAGE_REDIRECTS_DIR-AlwaysEmptied-Setup.cmake b/Tests/RunCMake/FetchContent_find_package/CMAKE_FIND_PACKAGE_REDIRECTS_DIR-AlwaysEmptied-Setup.cmake
new file mode 100644
index 0000000..ea36bf0
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/CMAKE_FIND_PACKAGE_REDIRECTS_DIR-AlwaysEmptied-Setup.cmake
@@ -0,0 +1,3 @@
+file(WRITE "${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/dummy_file.txt"
+ "This file should be deleted the next time CMake runs"
+)
diff --git a/Tests/RunCMake/FetchContent_find_package/CMAKE_FIND_PACKAGE_REDIRECTS_DIR-AlwaysEmptied.cmake b/Tests/RunCMake/FetchContent_find_package/CMAKE_FIND_PACKAGE_REDIRECTS_DIR-AlwaysEmptied.cmake
new file mode 100644
index 0000000..07c45f2
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/CMAKE_FIND_PACKAGE_REDIRECTS_DIR-AlwaysEmptied.cmake
@@ -0,0 +1,9 @@
+file(GLOB contents LIST_DIRECTORIES true "${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/*")
+
+if(NOT contents STREQUAL "")
+ list(JOIN contents "\n" fileList)
+ message(FATAL_ERROR
+ "CMAKE_FIND_PACKAGE_REDIRECTS_DIR is not empty:\n"
+ "${fileList}"
+ )
+endif()
diff --git a/Tests/RunCMake/FetchContent_find_package/CMAKE_FIND_PACKAGE_REDIRECTS_DIR-Exists.cmake b/Tests/RunCMake/FetchContent_find_package/CMAKE_FIND_PACKAGE_REDIRECTS_DIR-Exists.cmake
new file mode 100644
index 0000000..dd01333
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/CMAKE_FIND_PACKAGE_REDIRECTS_DIR-Exists.cmake
@@ -0,0 +1,18 @@
+if(NOT DEFINED CMAKE_FIND_PACKAGE_REDIRECTS_DIR)
+ message(FATAL_ERROR "CMAKE_FIND_PACKAGE_REDIRECTS_DIR is not defined")
+endif()
+
+if(NOT CMAKE_FIND_PACKAGE_REDIRECTS_DIR STREQUAL "${CMAKE_BINARY_DIR}/CMakeFiles/pkgRedirects")
+ message(FATAL_ERROR
+ "CMAKE_FIND_PACKAGE_REDIRECTS_DIR has wrong value\n"
+ " Expected: ${CMAKE_BINARY_DIR}/CMakeFiles/pkgRedirects\n"
+ " Actual: ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}"
+ )
+endif()
+
+if(NOT EXISTS "${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}")
+ message(FATAL_ERROR
+ "Directory CMAKE_FIND_PACKAGE_REDIRECTS_DIR points to does not exist:\n"
+ "${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}"
+ )
+endif()
diff --git a/Tests/RunCMake/FetchContent_find_package/CMakeLists.txt b/Tests/RunCMake/FetchContent_find_package/CMakeLists.txt
new file mode 100644
index 0000000..bd718c7
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 3.23)
+project(${RunCMake_TEST} NONE)
+
+# Tests assume no previous downloads in the output directory
+file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/_deps)
+
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/FetchContent_find_package/FatalIfAdded/CMakeLists.txt b/Tests/RunCMake/FetchContent_find_package/FatalIfAdded/CMakeLists.txt
new file mode 100644
index 0000000..6a3b931
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/FatalIfAdded/CMakeLists.txt
@@ -0,0 +1 @@
+message(FATAL_ERROR "Unexpectedly added directory via FetchContent_MakeAvailable()")
diff --git a/Tests/RunCMake/FetchContent_find_package/MissingDetails-result.txt b/Tests/RunCMake/FetchContent_find_package/MissingDetails-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/MissingDetails-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/FetchContent_find_package/MissingDetails-stderr.txt b/Tests/RunCMake/FetchContent_find_package/MissingDetails-stderr.txt
new file mode 100644
index 0000000..c4f1daf
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/MissingDetails-stderr.txt
@@ -0,0 +1 @@
+No content details recorded for t1
diff --git a/Tests/RunCMake/FetchContent_find_package/MissingDetails.cmake b/Tests/RunCMake/FetchContent_find_package/MissingDetails.cmake
new file mode 100644
index 0000000..ba8d121
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/MissingDetails.cmake
@@ -0,0 +1,3 @@
+include(FetchContent)
+
+FetchContent_Populate(t1)
diff --git a/Tests/RunCMake/FetchContent_find_package/PackageConfigs/AddedProjectConfig.cmake b/Tests/RunCMake/FetchContent_find_package/PackageConfigs/AddedProjectConfig.cmake
new file mode 100644
index 0000000..a38159f
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/PackageConfigs/AddedProjectConfig.cmake
@@ -0,0 +1,2 @@
+set(AddedProject_FOUND TRUE)
+message(STATUS "Loaded AddedProject from package config")
diff --git a/Tests/RunCMake/FetchContent_find_package/PackageConfigs/FirstProjectConfig.cmake b/Tests/RunCMake/FetchContent_find_package/PackageConfigs/FirstProjectConfig.cmake
new file mode 100644
index 0000000..3a89969
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/PackageConfigs/FirstProjectConfig.cmake
@@ -0,0 +1,2 @@
+set(FirstProject_FOUND TRUE)
+message(STATUS "Loaded FirstProject from package config")
diff --git a/Tests/RunCMake/FetchContent_find_package/PackageConfigs/SecondProjectConfig.cmake b/Tests/RunCMake/FetchContent_find_package/PackageConfigs/SecondProjectConfig.cmake
new file mode 100644
index 0000000..a181ab8
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/PackageConfigs/SecondProjectConfig.cmake
@@ -0,0 +1 @@
+message(FATAL_ERROR "Unexpectedly found SecondProject via find_package()")
diff --git a/Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindFirstProject.cmake b/Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindFirstProject.cmake
new file mode 100644
index 0000000..bdd3369
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindFirstProject.cmake
@@ -0,0 +1 @@
+message(FATAL_ERROR "First project used Find module")
diff --git a/Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindSecondProject.cmake b/Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindSecondProject.cmake
new file mode 100644
index 0000000..09a4acf
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindSecondProject.cmake
@@ -0,0 +1 @@
+message(FATAL_ERROR "Second project used Find module")
diff --git a/Tests/RunCMake/FetchContent_find_package/PreferFetchContent-stdout.txt b/Tests/RunCMake/FetchContent_find_package/PreferFetchContent-stdout.txt
new file mode 100644
index 0000000..5413a4b
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/PreferFetchContent-stdout.txt
@@ -0,0 +1,3 @@
+Confirmation project has been added
+(-- )?Lowercase extra file was read
+(-- )?Uppercase extra file was read
diff --git a/Tests/RunCMake/FetchContent_find_package/PreferFetchContent.cmake b/Tests/RunCMake/FetchContent_find_package/PreferFetchContent.cmake
new file mode 100644
index 0000000..c1030fb
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/PreferFetchContent.cmake
@@ -0,0 +1,20 @@
+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)
diff --git a/Tests/RunCMake/FetchContent_find_package/Prefer_find_package-stdout.txt b/Tests/RunCMake/FetchContent_find_package/Prefer_find_package-stdout.txt
new file mode 100644
index 0000000..dfb4238
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/Prefer_find_package-stdout.txt
@@ -0,0 +1,3 @@
+Loaded AddedProject from package config
+.*Loaded AddedProject from package config
+.*Loaded AddedProject from package config
diff --git a/Tests/RunCMake/FetchContent_find_package/Prefer_find_package.cmake b/Tests/RunCMake/FetchContent_find_package/Prefer_find_package.cmake
new file mode 100644
index 0000000..f5454ab
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/Prefer_find_package.cmake
@@ -0,0 +1,15 @@
+include(FetchContent)
+
+set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_LIST_DIR}/PackageConfigs)
+
+FetchContent_Declare(
+ AddedProject
+ # Ensure failure if we don't re-route to find_package()
+ SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/FatalIfAdded
+ FIND_PACKAGE_ARGS REQUIRED
+)
+
+# Cycle through a few calls to exercise global property changes
+FetchContent_MakeAvailable(AddedProject)
+find_package(AddedProject REQUIRED)
+FetchContent_MakeAvailable(AddedProject) # Will re-route to find_package() again
diff --git a/Tests/RunCMake/FetchContent_find_package/PreserveEmptyArgs-stdout.txt b/Tests/RunCMake/FetchContent_find_package/PreserveEmptyArgs-stdout.txt
new file mode 100644
index 0000000..a72d914
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/PreserveEmptyArgs-stdout.txt
@@ -0,0 +1,4 @@
+.*-- Number of arguments: 6
+.*-- Argument 3: 'before'
+.*-- Argument 4: ''
+.*-- Argument 5: 'after'
diff --git a/Tests/RunCMake/FetchContent_find_package/PreserveEmptyArgs.cmake b/Tests/RunCMake/FetchContent_find_package/PreserveEmptyArgs.cmake
new file mode 100644
index 0000000..4f35448
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/PreserveEmptyArgs.cmake
@@ -0,0 +1,13 @@
+include(FetchContent)
+
+# Need to see the download command output
+set(FETCHCONTENT_QUIET OFF)
+
+FetchContent_Declare(
+ t1
+ DOWNLOAD_COMMAND ${CMAKE_COMMAND} -P
+ ${CMAKE_CURRENT_LIST_DIR}/countArgs.cmake
+ before "" after
+)
+
+FetchContent_Populate(t1)
diff --git a/Tests/RunCMake/FetchContent_find_package/ProjectProvidesPackageConfigFiles-stdout.txt b/Tests/RunCMake/FetchContent_find_package/ProjectProvidesPackageConfigFiles-stdout.txt
new file mode 100644
index 0000000..76c6916
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/ProjectProvidesPackageConfigFiles-stdout.txt
@@ -0,0 +1,4 @@
+(-- )?ConfigForm1 override successful
+(-- )?ConfigForm2 override successful
+(-- )?ConfigForm1_VERSION = 1.8
+(-- )?ConfigForm2_VERSION = 1.9.7
diff --git a/Tests/RunCMake/FetchContent_find_package/ProjectProvidesPackageConfigFiles.cmake b/Tests/RunCMake/FetchContent_find_package/ProjectProvidesPackageConfigFiles.cmake
new file mode 100644
index 0000000..32e3f73
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/ProjectProvidesPackageConfigFiles.cmake
@@ -0,0 +1,40 @@
+include(FetchContent)
+
+FetchContent_Declare(
+ ConfigForm1
+ SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/FatalIfAdded
+ FIND_PACKAGE_ARGS 1.8 EXACT REQUIRED
+)
+file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/ConfigForm1Config.cmake [[
+set(ConfigForm1_FOUND TRUE)
+message(STATUS "ConfigForm1 override successful")
+]]
+)
+file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/ConfigForm1ConfigVersion.cmake [[
+set(PACKAGE_VERSION 1.8)
+set(PACKAGE_VERSION_EXACT TRUE)
+set(PACKAGE_VERSION_COMPATIBLE TRUE)
+]]
+)
+
+FetchContent_Declare(
+ ConfigForm2
+ SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/FatalIfAdded
+ FIND_PACKAGE_ARGS 1.8 REQUIRED
+)
+file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/configform2-config.cmake [[
+set(ConfigForm2_FOUND TRUE)
+message(STATUS "ConfigForm2 override successful")
+]]
+)
+file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/configform2-config-version.cmake [[
+set(PACKAGE_VERSION 1.9.7)
+set(PACKAGE_VERSION_EXACT FALSE)
+set(PACKAGE_VERSION_COMPATIBLE TRUE)
+]]
+)
+
+FetchContent_MakeAvailable(ConfigForm1 ConfigForm2)
+
+message(STATUS "ConfigForm1_VERSION = ${ConfigForm1_VERSION}")
+message(STATUS "ConfigForm2_VERSION = ${ConfigForm2_VERSION}")
diff --git a/Tests/RunCMake/FetchContent_find_package/Redirect_find_package_MODULE-stdout.txt b/Tests/RunCMake/FetchContent_find_package/Redirect_find_package_MODULE-stdout.txt
new file mode 100644
index 0000000..fbe6e38
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/Redirect_find_package_MODULE-stdout.txt
@@ -0,0 +1,9 @@
+(-- )?find_package\(FirstProject\):
+(-- )?Confirmation project has been added
+(-- )?FirstProject_FOUND = 1
+(-- )?FetchContent_MakeAvailable\(FirstProject\):
+(-- )?FetchContent_MakeAvailable\(SecondProject\):
+(-- )?Confirmation project has been added
+(-- )?find_package\(SecondProject\):
+(-- )?SecondProject_FOUND = 1
+(-- )?End of test
diff --git a/Tests/RunCMake/FetchContent_find_package/Redirect_find_package_MODULE.cmake b/Tests/RunCMake/FetchContent_find_package/Redirect_find_package_MODULE.cmake
new file mode 100644
index 0000000..95bc2dc
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/Redirect_find_package_MODULE.cmake
@@ -0,0 +1,39 @@
+include(FetchContent)
+
+set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_LIST_DIR}/PackageConfigs)
+
+FetchContent_Declare(
+ FirstProject
+ SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/AddedProject
+ OVERRIDE_FIND_PACKAGE
+)
+FetchContent_Declare(
+ SecondProject
+ SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/AddedProject
+ # Allow a call to find_package() that we know will fail.
+ # This enables redirection of calls to find_package(SecondProject)
+ # after FetchContent_MakeAvailable() populates.
+ FIND_PACKAGE_ARGS NAMES I_do_not_exist
+)
+
+set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/PackageFindModules)
+
+# Re-directs to FetchContent_MakeAvailable()
+message(STATUS "find_package(FirstProject):")
+find_package(FirstProject REQUIRED MODULE)
+message(STATUS "FirstProject_FOUND = ${FirstProject_FOUND}")
+
+# Does nothing, already populated
+message(STATUS "FetchContent_MakeAvailable(FirstProject):")
+FetchContent_MakeAvailable(FirstProject)
+
+# Populates as normal
+message(STATUS "FetchContent_MakeAvailable(SecondProject):")
+FetchContent_MakeAvailable(SecondProject)
+
+# Redirects to config package file created by previous command
+message(STATUS "find_package(SecondProject):")
+find_package(SecondProject REQUIRED MODULE)
+message(STATUS "SecondProject_FOUND = ${FirstProject_FOUND}")
+
+message(STATUS "End of test")
diff --git a/Tests/RunCMake/FetchContent_find_package/RunCMakeTest.cmake b/Tests/RunCMake/FetchContent_find_package/RunCMakeTest.cmake
new file mode 100644
index 0000000..c139f57
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/RunCMakeTest.cmake
@@ -0,0 +1,22 @@
+include(RunCMake)
+
+unset(RunCMake_TEST_NO_CLEAN)
+
+function(run_FetchContent_pkgRedirects)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CMAKE_FIND_PACKAGE_REDIRECTS_DIR-AlwaysEmptied-build)
+ run_cmake(CMAKE_FIND_PACKAGE_REDIRECTS_DIR-AlwaysEmptied-Setup)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ run_cmake(CMAKE_FIND_PACKAGE_REDIRECTS_DIR-AlwaysEmptied)
+endfunction()
+
+run_cmake(CMAKE_FIND_PACKAGE_REDIRECTS_DIR-Exists)
+run_FetchContent_pkgRedirects()
+run_cmake(BadArgs_find_package)
+run_cmake(PreferFetchContent)
+run_cmake(Prefer_find_package)
+run_cmake(ProjectProvidesPackageConfigFiles)
+run_cmake(Try_find_package-ALWAYS)
+run_cmake(Try_find_package-NEVER)
+run_cmake(Try_find_package-OPT_IN)
+run_cmake(Try_find_package-BOGUS)
+run_cmake(Redirect_find_package_MODULE)
diff --git a/Tests/RunCMake/FetchContent_find_package/Try_find_package-ALWAYS-stdout.txt b/Tests/RunCMake/FetchContent_find_package/Try_find_package-ALWAYS-stdout.txt
new file mode 100644
index 0000000..d43b8e8
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/Try_find_package-ALWAYS-stdout.txt
@@ -0,0 +1,2 @@
+Loaded FirstProject from package config
+(-- )?Confirmation project has been added
diff --git a/Tests/RunCMake/FetchContent_find_package/Try_find_package-ALWAYS.cmake b/Tests/RunCMake/FetchContent_find_package/Try_find_package-ALWAYS.cmake
new file mode 100644
index 0000000..0d7e289
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/Try_find_package-ALWAYS.cmake
@@ -0,0 +1,18 @@
+include(FetchContent)
+
+set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_LIST_DIR}/PackageConfigs)
+set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE ALWAYS)
+
+FetchContent_Declare(
+ FirstProject
+ # Ensure failure if we don't re-route to find_package()
+ SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/FatalIfAdded
+)
+
+FetchContent_Declare(
+ SecondProject
+ SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/AddedProject
+ OVERRIDE_FIND_PACKAGE # Takes precedence over ALWAYS mode
+)
+
+FetchContent_MakeAvailable(FirstProject SecondProject)
diff --git a/Tests/RunCMake/FetchContent_find_package/Try_find_package-BOGUS-result.txt b/Tests/RunCMake/FetchContent_find_package/Try_find_package-BOGUS-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/Try_find_package-BOGUS-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/FetchContent_find_package/Try_find_package-BOGUS-stderr.txt b/Tests/RunCMake/FetchContent_find_package/Try_find_package-BOGUS-stderr.txt
new file mode 100644
index 0000000..4cc7347
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/Try_find_package-BOGUS-stderr.txt
@@ -0,0 +1,2 @@
+CMake Error at .*/FetchContent.cmake:[0-9]+ \(message\):
+ Unsupported value for FETCHCONTENT_TRY_FIND_PACKAGE_MODE: BOGUS
diff --git a/Tests/RunCMake/FetchContent_find_package/Try_find_package-BOGUS.cmake b/Tests/RunCMake/FetchContent_find_package/Try_find_package-BOGUS.cmake
new file mode 100644
index 0000000..f9c8ce7
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/Try_find_package-BOGUS.cmake
@@ -0,0 +1,8 @@
+include(FetchContent)
+
+set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE BOGUS)
+
+FetchContent_Declare(
+ AddedProject
+ SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/AddedProject
+)
diff --git a/Tests/RunCMake/FetchContent_find_package/Try_find_package-NEVER-stdout.txt b/Tests/RunCMake/FetchContent_find_package/Try_find_package-NEVER-stdout.txt
new file mode 100644
index 0000000..52398e7
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/Try_find_package-NEVER-stdout.txt
@@ -0,0 +1 @@
+Confirmation project has been added
diff --git a/Tests/RunCMake/FetchContent_find_package/Try_find_package-NEVER.cmake b/Tests/RunCMake/FetchContent_find_package/Try_find_package-NEVER.cmake
new file mode 100644
index 0000000..92cb7d0
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/Try_find_package-NEVER.cmake
@@ -0,0 +1,12 @@
+include(FetchContent)
+
+set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_LIST_DIR}/PackageConfigs)
+set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE NEVER)
+
+FetchContent_Declare(
+ AddedProject
+ SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/AddedProject
+ FIND_PACKAGE_ARGS REQUIRED
+)
+
+FetchContent_MakeAvailable(AddedProject)
diff --git a/Tests/RunCMake/FetchContent_find_package/Try_find_package-OPT_IN-stdout.txt b/Tests/RunCMake/FetchContent_find_package/Try_find_package-OPT_IN-stdout.txt
new file mode 100644
index 0000000..d43b8e8
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/Try_find_package-OPT_IN-stdout.txt
@@ -0,0 +1,2 @@
+Loaded FirstProject from package config
+(-- )?Confirmation project has been added
diff --git a/Tests/RunCMake/FetchContent_find_package/Try_find_package-OPT_IN.cmake b/Tests/RunCMake/FetchContent_find_package/Try_find_package-OPT_IN.cmake
new file mode 100644
index 0000000..a549583
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/Try_find_package-OPT_IN.cmake
@@ -0,0 +1,20 @@
+include(FetchContent)
+
+set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_LIST_DIR}/PackageConfigs)
+set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE OPT_IN)
+
+# With opt-in, should call find_package()
+FetchContent_Declare(
+ FirstProject
+ # Ensure failure if we don't re-route to find_package()
+ SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/FatalIfAdded
+ FIND_PACKAGE_ARGS REQUIRED
+)
+
+# Without opt-in, shouldn't call find_package()
+FetchContent_Declare(
+ SecondProject
+ SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/AddedProject
+)
+
+FetchContent_MakeAvailable(FirstProject SecondProject)
diff --git a/Tests/RunCMake/find_package/FromPATHEnv-stderr.txt b/Tests/RunCMake/find_package/FromPATHEnv-stderr.txt
index 691d7f0..fdf098d 100644
--- a/Tests/RunCMake/find_package/FromPATHEnv-stderr.txt
+++ b/Tests/RunCMake/find_package/FromPATHEnv-stderr.txt
@@ -6,6 +6,11 @@
The file was not found.
+ The internally managed CMAKE_FIND_PACKAGE_REDIRECTS_DIR.
+
+ [^
+]*/Tests/RunCMake/find_package/FromPATHEnv-build/CMakeFiles/pkgRedirects
+
<PackageName>_ROOT CMake variable \[CMAKE_FIND_USE_PACKAGE_ROOT_PATH\].
none
@@ -69,6 +74,10 @@
module:
[^
+]*/Tests/RunCMake/find_package/FromPATHEnv-build/CMakeFiles/pkgRedirects/ResolvedConfig.cmake
+ [^
+]*/Tests/RunCMake/find_package/FromPATHEnv-build/CMakeFiles/pkgRedirects/resolved-config.cmake
+ [^
]*/Tests/RunCMake/find_package/PackageRoot/ResolvedConfig.cmake
The file was found at
diff --git a/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt b/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt
index ef5ec33..5140616 100644
--- a/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt
+++ b/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt
@@ -6,6 +6,11 @@
The file was not found.
+ The internally managed CMAKE_FIND_PACKAGE_REDIRECTS_DIR.
+
+ [^
+]*/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-build/CMakeFiles/pkgRedirects
+
<PackageName>_ROOT CMake variable \[CMAKE_FIND_USE_PACKAGE_ROOT_PATH\].
none
@@ -69,6 +74,10 @@
module:
[^
+]*/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-build/CMakeFiles/pkgRedirects/ResolvedConfig.cmake
+ [^
+]*/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-build/CMakeFiles/pkgRedirects/resolved-config.cmake
+ [^
]*/Tests/RunCMake/find_package/PackageRoot/ResolvedConfig.cmake
The file was found at
diff --git a/Tests/RunCMake/find_package/ModuleModeDebugPkg-stderr.txt b/Tests/RunCMake/find_package/ModuleModeDebugPkg-stderr.txt
index e4fd7c5..9757803 100644
--- a/Tests/RunCMake/find_package/ModuleModeDebugPkg-stderr.txt
+++ b/Tests/RunCMake/find_package/ModuleModeDebugPkg-stderr.txt
@@ -97,6 +97,11 @@ Call Stack \(most recent call first\):
FindBar processed here.
+
CMake Debug Log at ModuleModeDebugPkg/FindFoo.cmake:[0-9]+ \(find_package\):
+ The internally managed CMAKE_FIND_PACKAGE_REDIRECTS_DIR.
+
+ [^
+]*/Tests/RunCMake/find_package/ModuleModeDebugPkg-build/CMakeFiles/pkgRedirects
+
Paths specified by the find_package HINTS option.
none
@@ -107,6 +112,11 @@ CMake Debug Log at ModuleModeDebugPkg/FindFoo.cmake:[0-9]+ \(find_package\):
find_package considered the following locations for Zot's Config module:
+ [^
+]*/Tests/RunCMake/find_package/ModuleModeDebugPkg-build/CMakeFiles/pkgRedirects/ZotConfig.cmake
+ [^
+]*/Tests/RunCMake/find_package/ModuleModeDebugPkg-build/CMakeFiles/pkgRedirects/zot-config.cmake
+
The file was not found.
Call Stack \(most recent call first\):