diff options
author | Brad King <brad.king@kitware.com> | 2019-07-16 13:12:56 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-07-16 13:12:56 (GMT) |
commit | 185e6a12884433caa65e55a44431bd76f52a9f48 (patch) | |
tree | e16546d8e1a046c76a4ef9807b75ba84c04f7064 | |
parent | 7242d812691e95cae578a597161693940447b38c (diff) | |
parent | f2edccea666662ce93af29e397c50702a675f3f4 (diff) | |
download | CMake-185e6a12884433caa65e55a44431bd76f52a9f48.zip CMake-185e6a12884433caa65e55a44431bd76f52a9f48.tar.gz CMake-185e6a12884433caa65e55a44431bd76f52a9f48.tar.bz2 |
Merge branch 'find_package-fix-NO_MODULE' into release-3.15
Merge-request: !3557
-rw-r--r-- | Source/cmFindPackageCommand.cxx | 5 | ||||
-rw-r--r-- | Tests/FindPackageTest/CMakeLists.txt | 33 | ||||
-rw-r--r-- | Tests/FindPackageTest/PreferConfigRecurse/ACMEConfig.cmake | 1 | ||||
-rw-r--r-- | Tests/FindPackageTest/PreferConfigRecurse/FindACME.cmake | 1 |
4 files changed, 38 insertions, 2 deletions
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 828488f..1d4a8ed 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -823,8 +823,9 @@ bool cmFindPackageCommand::HandlePackageMode( } } - if (this->Makefile->IsOn("CMAKE_FIND_PACKAGE_PREFER_CONFIG") && !found && - handlePackageModeType == HandlePackageModeType::Config) { + if (this->UseFindModules && !found && + handlePackageModeType == HandlePackageModeType::Config && + this->Makefile->IsOn("CMAKE_FIND_PACKAGE_PREFER_CONFIG")) { // Config mode failed. Allow Module case. result = false; } diff --git a/Tests/FindPackageTest/CMakeLists.txt b/Tests/FindPackageTest/CMakeLists.txt index affe5d5..da79f5d 100644 --- a/Tests/FindPackageTest/CMakeLists.txt +++ b/Tests/FindPackageTest/CMakeLists.txt @@ -579,6 +579,26 @@ endif() set(CMAKE_FIND_PACKAGE_PREFER_CONFIG OFF) set(CMAKE_PREFIX_PATH) +set(CMAKE_MODULE_PATH) + +############################################################################ +##Test FIND_PACKAGE CMAKE_FIND_PACKAGE_PREFER_CONFIG - Do not recurse + +# No CMAKE_PREFIX_PATH +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/PreferConfigRecurse) + +# Now prefer config mode +set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON) +unset(ACME_FOUND) +unset(ACME_CONFIG) + +find_package(ACME) +if(ACME_FOUND AND ACME_CONFIG) + message(SEND_ERROR "Incorrectly found ACME in CONFIG mode, from the MODULE package") +endif() + +set(CMAKE_FIND_PACKAGE_PREFER_CONFIG OFF) +set(CMAKE_MODULE_PATH) ############################################################################ ##Test find_package CMAKE_FIND_PACKAGE_PREFER_CONFIG with module fallback @@ -592,3 +612,16 @@ find_package(ACME REQUIRED) if(NOT ACME_FOUND) message(SEND_ERROR "Did not find ACME package") endif() + +############################################################################ +##Test find_package CMAKE_FIND_PACKAGE_PREFER_CONFIG with NO_MODULE + +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/PreferConfigOnlyModule) + +set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON) + +find_package(ACME NO_MODULE) + +if(ACME_FOUND) + message(SEND_ERROR "Should not find ACME package") +endif() diff --git a/Tests/FindPackageTest/PreferConfigRecurse/ACMEConfig.cmake b/Tests/FindPackageTest/PreferConfigRecurse/ACMEConfig.cmake new file mode 100644 index 0000000..7a4e1b3 --- /dev/null +++ b/Tests/FindPackageTest/PreferConfigRecurse/ACMEConfig.cmake @@ -0,0 +1 @@ +set(ACME_FOUND TRUE) diff --git a/Tests/FindPackageTest/PreferConfigRecurse/FindACME.cmake b/Tests/FindPackageTest/PreferConfigRecurse/FindACME.cmake new file mode 100644 index 0000000..9bdc7db --- /dev/null +++ b/Tests/FindPackageTest/PreferConfigRecurse/FindACME.cmake @@ -0,0 +1 @@ +find_package(ACME NO_MODULE) |