mirror of
https://github.com/Kitware/CMake.git
synced 2026-08-04 14:50:23 +00:00
cmFindPackageCommand: Split condition to improve readability
This commit is contained in:
committed by
Brad King
parent
4717797647
commit
d9df805f6a
@@ -727,104 +727,110 @@ bool cmFindPackageCommand::HandlePackageMode()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result && !found && (!this->Quiet || this->Required)) {
|
// package not found
|
||||||
// The variable is not set.
|
if (result && !found) {
|
||||||
std::ostringstream e;
|
// warn if package required and not quiet
|
||||||
std::ostringstream aw;
|
if (!this->Quiet || this->Required) {
|
||||||
if (configFileSetFOUNDFalse) {
|
// The variable is not set.
|
||||||
/* clang-format off */
|
std::ostringstream e;
|
||||||
e << "Found package configuration file:\n"
|
std::ostringstream aw;
|
||||||
" " << this->FileFound << "\n"
|
if (configFileSetFOUNDFalse) {
|
||||||
"but it set " << foundVar << " to FALSE so package \"" <<
|
/* clang-format off */
|
||||||
this->Name << "\" is considered to be NOT FOUND.";
|
e << "Found package configuration file:\n"
|
||||||
/* clang-format on */
|
" " << this->FileFound << "\n"
|
||||||
if (!notFoundMessage.empty()) {
|
"but it set " << foundVar << " to FALSE so package \"" <<
|
||||||
e << " Reason given by package: \n" << notFoundMessage << "\n";
|
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
|
||||||
// If there are files in ConsideredConfigs, it means that FooConfig.cmake
|
// have been found, but they didn't have appropriate versions.
|
||||||
// have been found, but they didn't have appropriate versions.
|
else if (!this->ConsideredConfigs.empty()) {
|
||||||
else if (!this->ConsideredConfigs.empty()) {
|
std::vector<ConfigFileInfo>::const_iterator duplicate_end =
|
||||||
std::vector<ConfigFileInfo>::const_iterator duplicate_end =
|
cmRemoveDuplicates(this->ConsideredConfigs);
|
||||||
cmRemoveDuplicates(this->ConsideredConfigs);
|
e << "Could not find a configuration file for package \"" << this->Name
|
||||||
e << "Could not find a configuration file for package \"" << this->Name
|
<< "\" that "
|
||||||
<< "\" that "
|
<< (this->VersionExact ? "exactly matches" : "is compatible with")
|
||||||
<< (this->VersionExact ? "exactly matches" : "is compatible with")
|
<< " requested version \"" << this->Version << "\".\n"
|
||||||
<< " requested version \"" << this->Version << "\".\n"
|
<< "The following configuration files were considered but not "
|
||||||
<< "The following configuration files were considered but not "
|
"accepted:\n";
|
||||||
"accepted:\n";
|
for (std::vector<ConfigFileInfo>::const_iterator i =
|
||||||
for (std::vector<ConfigFileInfo>::const_iterator i =
|
this->ConsideredConfigs.begin();
|
||||||
this->ConsideredConfigs.begin();
|
i != duplicate_end; ++i) {
|
||||||
i != duplicate_end; ++i) {
|
e << " " << i->filename << ", version: " << i->version << "\n";
|
||||||
e << " " << i->filename << ", version: " << i->version << "\n";
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
std::string requestedVersionString;
|
||||||
std::string requestedVersionString;
|
if (!this->Version.empty()) {
|
||||||
if (!this->Version.empty()) {
|
requestedVersionString = " (requested version ";
|
||||||
requestedVersionString = " (requested version ";
|
requestedVersionString += this->Version;
|
||||||
requestedVersionString += this->Version;
|
requestedVersionString += ")";
|
||||||
requestedVersionString += ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
if (this->UseConfigFiles) {
|
||||||
e << "Could not find a package configuration file named \""
|
if (this->UseFindModules) {
|
||||||
<< this->Configs[0] << "\" provided by package \"" << this->Name
|
e << "By not providing \"Find" << this->Name
|
||||||
<< "\"" << requestedVersionString << ".\n";
|
<< ".cmake\" in "
|
||||||
} else {
|
"CMAKE_MODULE_PATH this project has asked CMake to find a "
|
||||||
e << "Could not find a package configuration file provided by \""
|
"package configuration file provided by \""
|
||||||
<< this->Name << "\"" << requestedVersionString
|
<< this->Name << "\", "
|
||||||
<< " with any of the following names:\n"
|
"but CMake did not find one.\n";
|
||||||
<< cmWrap(" ", this->Configs, "", "\n") << "\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";
|
||||||
}
|
}
|
||||||
|
|
||||||
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->Makefile->IssueMessage(
|
||||||
this->Required ? cmake::FATAL_ERROR : cmake::WARNING, e.str());
|
this->Required ? cmake::FATAL_ERROR : cmake::WARNING, e.str());
|
||||||
if (this->Required) {
|
if (this->Required) {
|
||||||
cmSystemTools::SetFatalErrorOccured();
|
cmSystemTools::SetFatalErrorOccured();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!aw.str().empty()) {
|
if (!aw.str().empty()) {
|
||||||
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, aw.str());
|
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, aw.str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user