summaryrefslogtreecommitdiffstats
path: root/Tests/FindPackageTest
diff options
context:
space:
mode:
authorCristian Adam <cristian.adam@gmail.com>2019-05-20 19:32:24 (GMT)
committerBrad King <brad.king@kitware.com>2019-05-21 14:29:47 (GMT)
commit26a99da206526efb203d0e448d7e095a07bec2fd (patch)
tree45d75b3710bdae0bc373993c2ad47788ce70cdb7 /Tests/FindPackageTest
parentc365243a3a282523062b5378898aa4fe6436f8fb (diff)
downloadCMake-26a99da206526efb203d0e448d7e095a07bec2fd.zip
CMake-26a99da206526efb203d0e448d7e095a07bec2fd.tar.gz
CMake-26a99da206526efb203d0e448d7e095a07bec2fd.tar.bz2
find_package: Add option to prefer Config mode
Add a `CMAKE_FIND_PACKAGE_PREFER_CONFIG` variable to tell `find_package` calls to look for a package configuration file first even if a find module is available. Fixes: #16805, #19236
Diffstat (limited to 'Tests/FindPackageTest')
-rw-r--r--Tests/FindPackageTest/CMakeLists.txt36
-rw-r--r--Tests/FindPackageTest/PreferConfig/ABCConfig.cmake1
-rw-r--r--Tests/FindPackageTest/PreferConfig/FindABC.cmake1
3 files changed, 37 insertions, 1 deletions
diff --git a/Tests/FindPackageTest/CMakeLists.txt b/Tests/FindPackageTest/CMakeLists.txt
index 6c876a7..8802b73 100644
--- a/Tests/FindPackageTest/CMakeLists.txt
+++ b/Tests/FindPackageTest/CMakeLists.txt
@@ -541,7 +541,41 @@ endif()
set(SortLib_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE)
unset(SortLib_VERSION)
-
unset(CMAKE_FIND_PACKAGE_SORT_ORDER)
unset(CMAKE_FIND_PACKAGE_SORT_DIRECTION)
set(CMAKE_PREFIX_PATH )
+
+############################################################################
+##Test FIND_PACKAGE CMAKE_FIND_PACKAGE_PREFER_CONFIG
+
+set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR}/PreferConfig)
+set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/PreferConfig)
+
+# prefer module mode
+set(CMAKE_FIND_PACKAGE_PREFER_CONFIG OFF)
+unset(ABC_FOUND)
+unset(ABC_CONFIG)
+
+find_package(ABC)
+if(NOT ABC_FOUND)
+ message(SEND_ERROR "Did not find ABC package")
+endif()
+if(ABC_CONFIG)
+ message(SEND_ERROR "Incorrectly found ABC in CONFIG mode, expected to find it with MODULE mode")
+endif()
+
+# Now prefer config mode
+set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
+unset(ABC_FOUND)
+unset(ABC_CONFIG)
+
+find_package(ABC)
+if(NOT ABC_FOUND)
+ message(SEND_ERROR "Did not find ABC package")
+endif()
+if(NOT ABC_CONFIG)
+ message(SEND_ERROR "Incorrectly found ABC in MODULE mode, expected to find it with CONFIG mode")
+endif()
+
+set(CMAKE_FIND_PACKAGE_PREFER_CONFIG OFF)
+set(CMAKE_PREFIX_PATH)
diff --git a/Tests/FindPackageTest/PreferConfig/ABCConfig.cmake b/Tests/FindPackageTest/PreferConfig/ABCConfig.cmake
new file mode 100644
index 0000000..281a5cd
--- /dev/null
+++ b/Tests/FindPackageTest/PreferConfig/ABCConfig.cmake
@@ -0,0 +1 @@
+set(ABC_FOUND TRUE)
diff --git a/Tests/FindPackageTest/PreferConfig/FindABC.cmake b/Tests/FindPackageTest/PreferConfig/FindABC.cmake
new file mode 100644
index 0000000..281a5cd
--- /dev/null
+++ b/Tests/FindPackageTest/PreferConfig/FindABC.cmake
@@ -0,0 +1 @@
+set(ABC_FOUND TRUE)