From d9df805f6a9433e579bc292c65b59efa5a87bceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Gr=C3=BCninger?= Date: Tue, 9 May 2017 07:04:53 +0200 Subject: cmFindPackageCommand: Split condition to improve readability --- Source/cmFindPackageCommand.cxx | 188 +++++++++++++++++++++------------------- 1 file changed, 97 insertions(+), 91 deletions(-) diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 17fa92c..1fbb97b 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -727,104 +727,110 @@ bool cmFindPackageCommand::HandlePackageMode() } } - if (result && !found && (!this->Quiet || this->Required)) { - // The variable is not set. - std::ostringstream e; - std::ostringstream aw; - if (configFileSetFOUNDFalse) { - /* clang-format off */ - e << "Found package configuration file:\n" - " " << this->FileFound << "\n" - "but it set " << foundVar << " to FALSE so package \"" << - this->Name << "\" is considered to be NOT FOUND."; - /* clang-format on */ - if (!notFoundMessage.empty()) { - e << " Reason given by package: \n" << notFoundMessage << "\n"; - } - } - // If there are files in ConsideredConfigs, it means that FooConfig.cmake - // have been found, but they didn't have appropriate versions. - else if (!this->ConsideredConfigs.empty()) { - std::vector::const_iterator duplicate_end = - cmRemoveDuplicates(this->ConsideredConfigs); - e << "Could not find a configuration file for package \"" << this->Name - << "\" that " - << (this->VersionExact ? "exactly matches" : "is compatible with") - << " requested version \"" << this->Version << "\".\n" - << "The following configuration files were considered but not " - "accepted:\n"; - for (std::vector::const_iterator i = - this->ConsideredConfigs.begin(); - i != duplicate_end; ++i) { - e << " " << i->filename << ", version: " << i->version << "\n"; - } - } else { - std::string requestedVersionString; - if (!this->Version.empty()) { - requestedVersionString = " (requested version "; - requestedVersionString += this->Version; - requestedVersionString += ")"; + // package not found + if (result && !found) { + // warn if package required and not quiet + if (!this->Quiet || this->Required) { + // The variable is not set. + std::ostringstream e; + std::ostringstream aw; + if (configFileSetFOUNDFalse) { + /* clang-format off */ + e << "Found package configuration file:\n" + " " << this->FileFound << "\n" + "but it set " << foundVar << " to FALSE so package \"" << + this->Name << "\" is considered to be NOT FOUND."; + /* clang-format on */ + if (!notFoundMessage.empty()) { + e << " Reason given by package: \n" << notFoundMessage << "\n"; + } } - - if (this->UseConfigFiles) { - if (this->UseFindModules) { - e << "By not providing \"Find" << this->Name - << ".cmake\" in " - "CMAKE_MODULE_PATH this project has asked CMake to find a " - "package configuration file provided by \"" - << this->Name << "\", " - "but CMake did not find one.\n"; + // If there are files in ConsideredConfigs, it means that FooConfig.cmake + // have been found, but they didn't have appropriate versions. + else if (!this->ConsideredConfigs.empty()) { + std::vector::const_iterator duplicate_end = + cmRemoveDuplicates(this->ConsideredConfigs); + e << "Could not find a configuration file for package \"" << this->Name + << "\" that " + << (this->VersionExact ? "exactly matches" : "is compatible with") + << " requested version \"" << this->Version << "\".\n" + << "The following configuration files were considered but not " + "accepted:\n"; + for (std::vector::const_iterator i = + this->ConsideredConfigs.begin(); + i != duplicate_end; ++i) { + e << " " << i->filename << ", version: " << i->version << "\n"; } - - if (this->Configs.size() == 1) { - e << "Could not find a package configuration file named \"" - << this->Configs[0] << "\" provided by package \"" << this->Name - << "\"" << requestedVersionString << ".\n"; - } else { - e << "Could not find a package configuration file provided by \"" - << this->Name << "\"" << requestedVersionString - << " with any of the following names:\n" - << cmWrap(" ", this->Configs, "", "\n") << "\n"; + } else { + std::string requestedVersionString; + if (!this->Version.empty()) { + requestedVersionString = " (requested version "; + requestedVersionString += this->Version; + requestedVersionString += ")"; } - e << "Add the installation prefix of \"" << this->Name - << "\" to " - "CMAKE_PREFIX_PATH or set \"" - << this->Variable << "\" to a " - "directory containing one of the above files. " - "If \"" - << this->Name << "\" provides a separate development " - "package or SDK, be sure it has been installed."; - } else // if(!this->UseFindModules && !this->UseConfigFiles) - { - e << "No \"Find" << this->Name << ".cmake\" found in " - << "CMAKE_MODULE_PATH."; - - aw << "Find" << this->Name - << ".cmake must either be part of this " - "project itself, in this case adjust CMAKE_MODULE_PATH so that " - "it points to the correct location inside its source tree.\n" - "Or it must be installed by a package which has already been " - "found via find_package(). In this case make sure that " - "package has indeed been found and adjust CMAKE_MODULE_PATH to " - "contain the location where that package has installed " - "Find" - << this->Name - << ".cmake. This must be a location " - "provided by that package. This error in general means that " - "the buildsystem of this project is relying on a Find-module " - "without ensuring that it is actually available.\n"; + if (this->UseConfigFiles) { + if (this->UseFindModules) { + e << "By not providing \"Find" << this->Name + << ".cmake\" in " + "CMAKE_MODULE_PATH this project has asked CMake to find a " + "package configuration file provided by \"" + << this->Name << "\", " + "but CMake did not find one.\n"; + } + + if (this->Configs.size() == 1) { + e << "Could not find a package configuration file named \"" + << this->Configs[0] << "\" provided by package \"" << this->Name + << "\"" << requestedVersionString << ".\n"; + } else { + e << "Could not find a package configuration file provided by \"" + << this->Name << "\"" << requestedVersionString + << " with any of the following names:\n" + << cmWrap(" ", this->Configs, "", "\n") << "\n"; + } + + e << "Add the installation prefix of \"" << this->Name + << "\" to " + "CMAKE_PREFIX_PATH or set \"" + << this->Variable + << "\" to a " + "directory containing one of the above files. " + "If \"" + << this->Name << "\" provides a separate development " + "package or SDK, be sure it has been installed."; + } else // if(!this->UseFindModules && !this->UseConfigFiles) + { + e << "No \"Find" << this->Name << ".cmake\" found in " + << "CMAKE_MODULE_PATH."; + + aw + << "Find" << this->Name + << ".cmake must either be part of this " + "project itself, in this case adjust CMAKE_MODULE_PATH so that " + "it points to the correct location inside its source tree.\n" + "Or it must be installed by a package which has already been " + "found via find_package(). In this case make sure that " + "package has indeed been found and adjust CMAKE_MODULE_PATH to " + "contain the location where that package has installed " + "Find" + << this->Name + << ".cmake. This must be a location " + "provided by that package. This error in general means that " + "the buildsystem of this project is relying on a Find-module " + "without ensuring that it is actually available.\n"; + } } - } - this->Makefile->IssueMessage( - this->Required ? cmake::FATAL_ERROR : cmake::WARNING, e.str()); - if (this->Required) { - cmSystemTools::SetFatalErrorOccured(); - } + this->Makefile->IssueMessage( + this->Required ? cmake::FATAL_ERROR : cmake::WARNING, e.str()); + if (this->Required) { + cmSystemTools::SetFatalErrorOccured(); + } - if (!aw.str().empty()) { - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, aw.str()); + if (!aw.str().empty()) { + this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, aw.str()); + } } } -- cgit v0.12 From d0b9d1cceb37a58bc953385e7a33c6dff543a14b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Gr=C3=BCninger?= Date: Tue, 9 May 2017 07:13:45 +0200 Subject: find_package: shorten output for missing package in config mode If CONFIG or MODULE is given and the package is not REQUIRED, output a one-liner instead of the full warning. Update Tests/RunCMake/find_package expected output to match. --- Source/cmFindPackageCommand.cxx | 12 ++++++++++-- Tests/RunCMake/find_package/MissingConfig-stderr.txt | 15 --------------- Tests/RunCMake/find_package/MissingConfig-stdout.txt | 1 + .../RunCMake/find_package/MissingConfigNormal-stdout.txt | 1 + .../RunCMake/find_package/MissingConfigOneName-stderr.txt | 10 ---------- .../RunCMake/find_package/MissingConfigOneName-stdout.txt | 1 + .../RunCMake/find_package/MissingConfigVersion-stderr.txt | 13 ------------- .../RunCMake/find_package/MissingConfigVersion-stdout.txt | 1 + Tests/RunCMake/find_package/SetFoundFALSE-stderr.txt | 9 --------- Tests/RunCMake/find_package/SetFoundFALSE-stdout.txt | 1 + 10 files changed, 15 insertions(+), 49 deletions(-) create mode 100644 Tests/RunCMake/find_package/MissingConfig-stdout.txt create mode 100644 Tests/RunCMake/find_package/MissingConfigNormal-stdout.txt delete mode 100644 Tests/RunCMake/find_package/MissingConfigOneName-stderr.txt create mode 100644 Tests/RunCMake/find_package/MissingConfigOneName-stdout.txt delete mode 100644 Tests/RunCMake/find_package/MissingConfigVersion-stderr.txt create mode 100644 Tests/RunCMake/find_package/MissingConfigVersion-stdout.txt delete mode 100644 Tests/RunCMake/find_package/SetFoundFALSE-stderr.txt create mode 100644 Tests/RunCMake/find_package/SetFoundFALSE-stdout.txt diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 1fbb97b..8f74ba8 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -729,8 +729,9 @@ bool cmFindPackageCommand::HandlePackageMode() // package not found if (result && !found) { - // warn if package required and not quiet - if (!this->Quiet || this->Required) { + // warn if package required or neither quiet nor in config mode + if (this->Required || + !(this->Quiet || (this->UseConfigFiles && !this->UseFindModules))) { // The variable is not set. std::ostringstream e; std::ostringstream aw; @@ -832,6 +833,13 @@ bool cmFindPackageCommand::HandlePackageMode() this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, aw.str()); } } + // output result if in config mode but not in quiet mode + else if (!this->Quiet) { + std::ostringstream aw; + aw << "Could NOT find " << this->Name << " (missing: " << this->Name + << "_DIR)"; + this->Makefile->DisplayStatus(aw.str().c_str(), -1); + } } // Set a variable marking whether the package was found. diff --git a/Tests/RunCMake/find_package/MissingConfig-stderr.txt b/Tests/RunCMake/find_package/MissingConfig-stderr.txt index 1eae0bb..33ff545 100644 --- a/Tests/RunCMake/find_package/MissingConfig-stderr.txt +++ b/Tests/RunCMake/find_package/MissingConfig-stderr.txt @@ -1,18 +1,3 @@ -CMake Warning at MissingConfig.cmake:1 \(find_package\): - Could not find a package configuration file provided by "NotHere" with any - of the following names: - - NotHereConfig.cmake - nothere-config.cmake - - Add the installation prefix of "NotHere" to CMAKE_PREFIX_PATH or set - "NotHere_DIR" to a directory containing one of the above files. If - "NotHere" provides a separate development package or SDK, be sure it has - been installed. -Call Stack \(most recent call first\): - CMakeLists.txt:3 \(include\) - - CMake Warning at MissingConfig.cmake:2 \(message\): This warning must be reachable. Call Stack \(most recent call first\): diff --git a/Tests/RunCMake/find_package/MissingConfig-stdout.txt b/Tests/RunCMake/find_package/MissingConfig-stdout.txt new file mode 100644 index 0000000..7af632b --- /dev/null +++ b/Tests/RunCMake/find_package/MissingConfig-stdout.txt @@ -0,0 +1 @@ +-- Could NOT find NotHere \(missing: NotHere_DIR\) diff --git a/Tests/RunCMake/find_package/MissingConfigNormal-stdout.txt b/Tests/RunCMake/find_package/MissingConfigNormal-stdout.txt new file mode 100644 index 0000000..7af632b --- /dev/null +++ b/Tests/RunCMake/find_package/MissingConfigNormal-stdout.txt @@ -0,0 +1 @@ +-- Could NOT find NotHere \(missing: NotHere_DIR\) diff --git a/Tests/RunCMake/find_package/MissingConfigOneName-stderr.txt b/Tests/RunCMake/find_package/MissingConfigOneName-stderr.txt deleted file mode 100644 index 10e71fa..0000000 --- a/Tests/RunCMake/find_package/MissingConfigOneName-stderr.txt +++ /dev/null @@ -1,10 +0,0 @@ -CMake Warning at MissingConfigOneName.cmake:1 \(find_package\): - Could not find a package configuration file named "NotHereConfig.cmake" - provided by package "NotHere". - - Add the installation prefix of "NotHere" to CMAKE_PREFIX_PATH or set - "NotHere_DIR" to a directory containing one of the above files. If - "NotHere" provides a separate development package or SDK, be sure it has - been installed. -Call Stack \(most recent call first\): - CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/find_package/MissingConfigOneName-stdout.txt b/Tests/RunCMake/find_package/MissingConfigOneName-stdout.txt new file mode 100644 index 0000000..7af632b --- /dev/null +++ b/Tests/RunCMake/find_package/MissingConfigOneName-stdout.txt @@ -0,0 +1 @@ +-- Could NOT find NotHere \(missing: NotHere_DIR\) diff --git a/Tests/RunCMake/find_package/MissingConfigVersion-stderr.txt b/Tests/RunCMake/find_package/MissingConfigVersion-stderr.txt deleted file mode 100644 index 2f5086e..0000000 --- a/Tests/RunCMake/find_package/MissingConfigVersion-stderr.txt +++ /dev/null @@ -1,13 +0,0 @@ -CMake Warning at MissingConfigVersion.cmake:1 \(find_package\): - Could not find a package configuration file provided by "NotHere" - \(requested version 1\.2\) with any of the following names: - - NotHereConfig.cmake - nothere-config.cmake - - Add the installation prefix of "NotHere" to CMAKE_PREFIX_PATH or set - "NotHere_DIR" to a directory containing one of the above files. If - "NotHere" provides a separate development package or SDK, be sure it has - been installed. -Call Stack \(most recent call first\): - CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/find_package/MissingConfigVersion-stdout.txt b/Tests/RunCMake/find_package/MissingConfigVersion-stdout.txt new file mode 100644 index 0000000..7af632b --- /dev/null +++ b/Tests/RunCMake/find_package/MissingConfigVersion-stdout.txt @@ -0,0 +1 @@ +-- Could NOT find NotHere \(missing: NotHere_DIR\) diff --git a/Tests/RunCMake/find_package/SetFoundFALSE-stderr.txt b/Tests/RunCMake/find_package/SetFoundFALSE-stderr.txt deleted file mode 100644 index 695f645..0000000 --- a/Tests/RunCMake/find_package/SetFoundFALSE-stderr.txt +++ /dev/null @@ -1,9 +0,0 @@ -CMake Warning at SetFoundFALSE.cmake:2 \(find_package\): - Found package configuration file: - - .*/Tests/RunCMake/find_package/SetFoundFALSEConfig.cmake - - but it set SetFoundFALSE_FOUND to FALSE so package "SetFoundFALSE" is - considered to be NOT FOUND. -Call Stack \(most recent call first\): - CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/find_package/SetFoundFALSE-stdout.txt b/Tests/RunCMake/find_package/SetFoundFALSE-stdout.txt new file mode 100644 index 0000000..37e6e7e --- /dev/null +++ b/Tests/RunCMake/find_package/SetFoundFALSE-stdout.txt @@ -0,0 +1 @@ +-- Could NOT find SetFoundFALSE \(missing: SetFoundFALSE_DIR\) -- cgit v0.12