find_package: add MODULE mode to use only Find-modules
The new mode differ from default mode in that that it doesn't fallback to config mode. The default mode stays unchanged.
This commit is contained in:
parent
7d67dcf52b
commit
f310f67291
@ -57,6 +57,7 @@ cmFindPackageCommand::cmFindPackageCommand()
|
|||||||
this->NoUserRegistry = false;
|
this->NoUserRegistry = false;
|
||||||
this->NoSystemRegistry = false;
|
this->NoSystemRegistry = false;
|
||||||
this->NoBuilds = false;
|
this->NoBuilds = false;
|
||||||
|
this->UseConfigFiles = true;
|
||||||
this->UseFindModules = true;
|
this->UseFindModules = true;
|
||||||
this->DebugMode = false;
|
this->DebugMode = false;
|
||||||
this->UseLib64Paths = false;
|
this->UseLib64Paths = false;
|
||||||
@ -86,7 +87,7 @@ void cmFindPackageCommand::GenerateDocumentation()
|
|||||||
cmSystemTools::ReplaceString(this->GenericDocumentationPathsOrder,
|
cmSystemTools::ReplaceString(this->GenericDocumentationPathsOrder,
|
||||||
"FIND_XXX", "find_package");
|
"FIND_XXX", "find_package");
|
||||||
this->CommandDocumentation =
|
this->CommandDocumentation =
|
||||||
" find_package(<package> [version] [EXACT] [QUIET]\n"
|
" find_package(<package> [version] [EXACT] [QUIET] [MODULE]\n"
|
||||||
" [[REQUIRED|COMPONENTS] [components...]]\n"
|
" [[REQUIRED|COMPONENTS] [components...]]\n"
|
||||||
" [NO_POLICY_SCOPE])\n"
|
" [NO_POLICY_SCOPE])\n"
|
||||||
"Finds and loads settings from an external project. "
|
"Finds and loads settings from an external project. "
|
||||||
@ -94,6 +95,7 @@ void cmFindPackageCommand::GenerateDocumentation()
|
|||||||
"When the package is found package-specific information is provided "
|
"When the package is found package-specific information is provided "
|
||||||
"through variables documented by the package itself. "
|
"through variables documented by the package itself. "
|
||||||
"The QUIET option disables messages if the package cannot be found. "
|
"The QUIET option disables messages if the package cannot be found. "
|
||||||
|
"The MODULE option disables the second signature documented below. "
|
||||||
"The REQUIRED option stops processing with an error message if the "
|
"The REQUIRED option stops processing with an error message if the "
|
||||||
"package cannot be found. "
|
"package cannot be found. "
|
||||||
"A package-specific list of components may be listed after the "
|
"A package-specific list of components may be listed after the "
|
||||||
@ -124,7 +126,8 @@ void cmFindPackageCommand::GenerateDocumentation()
|
|||||||
"and producing any needed messages. "
|
"and producing any needed messages. "
|
||||||
"Many find-modules provide limited or no support for versioning; "
|
"Many find-modules provide limited or no support for versioning; "
|
||||||
"check the module documentation. "
|
"check the module documentation. "
|
||||||
"If no module is found the command proceeds to Config mode.\n"
|
"If no module is found and the MODULE option is not given the command "
|
||||||
|
"proceeds to Config mode.\n"
|
||||||
"The complete Config mode command signature is:\n"
|
"The complete Config mode command signature is:\n"
|
||||||
" find_package(<package> [version] [EXACT] [QUIET]\n"
|
" find_package(<package> [version] [EXACT] [QUIET]\n"
|
||||||
" [[REQUIRED|COMPONENTS] [components...]] [NO_MODULE]\n"
|
" [[REQUIRED|COMPONENTS] [components...]] [NO_MODULE]\n"
|
||||||
@ -410,6 +413,7 @@ bool cmFindPackageCommand
|
|||||||
Doing doing = DoingNone;
|
Doing doing = DoingNone;
|
||||||
cmsys::RegularExpression version("^[0-9.]+$");
|
cmsys::RegularExpression version("^[0-9.]+$");
|
||||||
bool haveVersion = false;
|
bool haveVersion = false;
|
||||||
|
std::string haveModeString = "";
|
||||||
for(unsigned int i=1; i < args.size(); ++i)
|
for(unsigned int i=1; i < args.size(); ++i)
|
||||||
{
|
{
|
||||||
if(args[i] == "QUIET")
|
if(args[i] == "QUIET")
|
||||||
@ -423,10 +427,35 @@ bool cmFindPackageCommand
|
|||||||
this->Compatibility_1_6 = false;
|
this->Compatibility_1_6 = false;
|
||||||
doing = DoingNone;
|
doing = DoingNone;
|
||||||
}
|
}
|
||||||
|
else if(args[i] == "MODULE")
|
||||||
|
{
|
||||||
|
if(!haveModeString.empty())
|
||||||
|
{
|
||||||
|
cmOStringStream e;
|
||||||
|
e << "given " << args[i] << ", but mode is already set to "
|
||||||
|
<< haveModeString << ".";
|
||||||
|
this->SetError(e.str().c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->UseConfigFiles = false;
|
||||||
|
doing = DoingNone;
|
||||||
|
haveModeString = args[i];
|
||||||
|
}
|
||||||
else if(args[i] == "NO_MODULE")
|
else if(args[i] == "NO_MODULE")
|
||||||
{
|
{
|
||||||
|
if(!haveModeString.empty())
|
||||||
|
{
|
||||||
|
cmOStringStream e;
|
||||||
|
e << "given " << args[i] << ", but mode is already set to "
|
||||||
|
<< haveModeString << ".";
|
||||||
|
this->SetError(e.str().c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
this->UseFindModules = false;
|
this->UseFindModules = false;
|
||||||
doing = DoingNone;
|
doing = DoingNone;
|
||||||
|
haveModeString = args[i];
|
||||||
}
|
}
|
||||||
else if(args[i] == "REQUIRED")
|
else if(args[i] == "REQUIRED")
|
||||||
{
|
{
|
||||||
@ -831,6 +860,8 @@ bool cmFindPackageCommand::HandlePackageMode()
|
|||||||
|
|
||||||
// Try to load the config file if the directory is known
|
// Try to load the config file if the directory is known
|
||||||
bool fileFound = false;
|
bool fileFound = false;
|
||||||
|
if (this->UseConfigFiles)
|
||||||
|
{
|
||||||
if(!cmSystemTools::IsOff(def))
|
if(!cmSystemTools::IsOff(def))
|
||||||
{
|
{
|
||||||
// Get the directory from the variable value.
|
// Get the directory from the variable value.
|
||||||
@ -867,6 +898,7 @@ bool cmFindPackageCommand::HandlePackageMode()
|
|||||||
cmake::INTERNAL_ERROR, "fileFound is true but FileFound is empty!");
|
cmake::INTERNAL_ERROR, "fileFound is true but FileFound is empty!");
|
||||||
fileFound = false;
|
fileFound = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If the directory for the config file was found, try to read the file.
|
// If the directory for the config file was found, try to read the file.
|
||||||
bool result = true;
|
bool result = true;
|
||||||
@ -893,6 +925,7 @@ bool cmFindPackageCommand::HandlePackageMode()
|
|||||||
{
|
{
|
||||||
// The variable is not set.
|
// The variable is not set.
|
||||||
cmOStringStream e;
|
cmOStringStream e;
|
||||||
|
cmOStringStream aw;
|
||||||
// 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.
|
||||||
if (this->ConsideredConfigs.size() > 0)
|
if (this->ConsideredConfigs.size() > 0)
|
||||||
@ -911,6 +944,8 @@ bool cmFindPackageCommand::HandlePackageMode()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if (this->UseConfigFiles)
|
||||||
{
|
{
|
||||||
if(this->UseFindModules)
|
if(this->UseFindModules)
|
||||||
{
|
{
|
||||||
@ -923,7 +958,8 @@ bool cmFindPackageCommand::HandlePackageMode()
|
|||||||
if(this->Configs.size() == 1)
|
if(this->Configs.size() == 1)
|
||||||
{
|
{
|
||||||
e << "Could not find a package configuration file named \""
|
e << "Could not find a package configuration file named \""
|
||||||
<< this->Configs[0] << "\" provided by package \"" << this->Name << "\".\n";
|
<< this->Configs[0] << "\" provided by package \""
|
||||||
|
<< this->Name << "\".\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -943,9 +979,33 @@ bool cmFindPackageCommand::HandlePackageMode()
|
|||||||
"If \"" << this->Name << "\" provides a separate development "
|
"If \"" << this->Name << "\" provides a separate development "
|
||||||
"package or SDK, be sure it has been installed.";
|
"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 (!aw.str().empty())
|
||||||
|
{
|
||||||
|
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,aw.str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set a variable marking whether the package was found.
|
// Set a variable marking whether the package was found.
|
||||||
|
@ -133,6 +133,7 @@ private:
|
|||||||
bool Quiet;
|
bool Quiet;
|
||||||
bool Required;
|
bool Required;
|
||||||
bool Compatibility_1_6;
|
bool Compatibility_1_6;
|
||||||
|
bool UseConfigFiles;
|
||||||
bool UseFindModules;
|
bool UseFindModules;
|
||||||
bool NoUserRegistry;
|
bool NoUserRegistry;
|
||||||
bool NoSystemRegistry;
|
bool NoSystemRegistry;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user