From 8ed868606ddae005b4a50319bdc291b8df5b525a Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Mon, 5 Aug 2019 23:46:54 +0200 Subject: find_package: Fix prefer-config mode to not fail on missing optional package When `CMAKE_FIND_PACKAGE_PREFER_CONFIG` mode was set to `ON`, failure to find a package was fatal even if it was not `REQUIRED`. Fix this and add a test case. Fixes: #19557 --- Source/cmFindPackageCommand.cxx | 4 +++- Tests/FindPackageTest/CMakeLists.txt | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 1d4a8ed..171fa77 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -507,7 +507,9 @@ bool cmFindPackageCommand::InitialPass(std::vector const& args, loadedPackage = true; } else { // The package was not loaded. Report errors. - HandlePackageMode(HandlePackageModeType::Module); + if (HandlePackageMode(HandlePackageModeType::Module)) { + loadedPackage = true; + } } } } else { diff --git a/Tests/FindPackageTest/CMakeLists.txt b/Tests/FindPackageTest/CMakeLists.txt index da79f5d..1b9c973 100644 --- a/Tests/FindPackageTest/CMakeLists.txt +++ b/Tests/FindPackageTest/CMakeLists.txt @@ -625,3 +625,9 @@ find_package(ACME NO_MODULE) if(ACME_FOUND) message(SEND_ERROR "Should not find ACME package") endif() + +############################################################################ +##Test find_package CMAKE_FIND_PACKAGE_PREFER_CONFIG with unknown package + +set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON) +find_package(DoesNotExist) -- cgit v0.12