ENH: Added NO_MODULE and COMPONENTS options to improve flexibility of the command. Re-implemented argument parsing to be simpler and more robust.
This commit is contained in:
parent
5418998e46
commit
d9f1d4d71a
@ -54,80 +54,80 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Record options.
|
||||||
this->Name = args[0];
|
this->Name = args[0];
|
||||||
|
|
||||||
// Build a list of required components.
|
|
||||||
std::string components;
|
|
||||||
const char* components_sep = "";
|
|
||||||
bool quiet = false;
|
bool quiet = false;
|
||||||
bool required = false;
|
bool required = false;
|
||||||
if(args.size() > 1)
|
bool no_module = false;
|
||||||
|
std::string components;
|
||||||
|
const char* components_sep = "";
|
||||||
|
|
||||||
|
// Parse the arguments.
|
||||||
|
bool doing_components = false;
|
||||||
|
cmsys::RegularExpression version("^[0-9.]+$");
|
||||||
|
bool haveVersion = false;
|
||||||
|
for(unsigned int i=1; i < args.size(); ++i)
|
||||||
{
|
{
|
||||||
cmsys::RegularExpression version("^[0-9.]+$");
|
if(args[i] == "QUIET")
|
||||||
bool haveVersion = false;
|
|
||||||
for(unsigned int i=1; i < args.size(); ++i)
|
|
||||||
{
|
{
|
||||||
if(!haveVersion && version.find(args[i].c_str()))
|
quiet = true;
|
||||||
{
|
doing_components = false;
|
||||||
haveVersion = true;
|
|
||||||
}
|
|
||||||
else if(args[i] == "QUIET")
|
|
||||||
{
|
|
||||||
quiet = true;
|
|
||||||
}
|
|
||||||
else if(args[i] == "REQUIRED")
|
|
||||||
{
|
|
||||||
// The package is required.
|
|
||||||
required = true;
|
|
||||||
|
|
||||||
// Look for a list of required components.
|
|
||||||
while(++i < args.size())
|
|
||||||
{
|
|
||||||
// Stop looking when a known keyword argument is
|
|
||||||
// encountered.
|
|
||||||
if((args[i] == "QUIET") ||
|
|
||||||
(args[i] == "REQUIRED"))
|
|
||||||
{
|
|
||||||
--i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Set a variable telling the find script this component
|
|
||||||
// is required.
|
|
||||||
std::string req_var = Name + "_FIND_REQUIRED_" + args[i];
|
|
||||||
this->Makefile->AddDefinition(req_var.c_str(), "1");
|
|
||||||
|
|
||||||
// Append to the list of required components.
|
|
||||||
components += components_sep;
|
|
||||||
components += args[i];
|
|
||||||
components_sep = ";";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cmOStringStream e;
|
|
||||||
e << "called with invalid argument \"" << args[i].c_str() << "\"";
|
|
||||||
this->SetError(e.str().c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else if(args[i] == "NO_MODULE")
|
||||||
|
{
|
||||||
|
no_module = true;
|
||||||
|
doing_components = false;
|
||||||
|
}
|
||||||
|
else if(args[i] == "REQUIRED")
|
||||||
|
{
|
||||||
|
required = true;
|
||||||
|
doing_components = true;
|
||||||
|
}
|
||||||
|
else if(args[i] == "COMPONENTS")
|
||||||
|
{
|
||||||
|
doing_components = true;
|
||||||
|
}
|
||||||
|
else if(doing_components)
|
||||||
|
{
|
||||||
|
// Set a variable telling the find script this component
|
||||||
|
// is required.
|
||||||
|
std::string req_var = Name + "_FIND_REQUIRED_" + args[i];
|
||||||
|
this->Makefile->AddDefinition(req_var.c_str(), "1");
|
||||||
|
|
||||||
// Store the list of components.
|
// Append to the list of required components.
|
||||||
std::string components_var = Name + "_FIND_COMPONENTS";
|
components += components_sep;
|
||||||
this->Makefile->AddDefinition(components_var.c_str(), components.c_str());
|
components += args[i];
|
||||||
|
components_sep = ";";
|
||||||
|
}
|
||||||
|
else if(!haveVersion && version.find(args[i].c_str()))
|
||||||
|
{
|
||||||
|
haveVersion = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cmOStringStream e;
|
||||||
|
e << "called with invalid argument \"" << args[i].c_str() << "\"";
|
||||||
|
this->SetError(e.str().c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store the list of components.
|
||||||
|
std::string components_var = Name + "_FIND_COMPONENTS";
|
||||||
|
this->Makefile->AddDefinition(components_var.c_str(), components.c_str());
|
||||||
|
|
||||||
// See if there is a Find<name>.cmake module.
|
// See if there is a Find<name>.cmake module.
|
||||||
bool foundModule = false;
|
if(!no_module)
|
||||||
if(!this->FindModule(foundModule, quiet, required))
|
|
||||||
{
|
{
|
||||||
return false;
|
bool foundModule = false;
|
||||||
}
|
if(!this->FindModule(foundModule, quiet, required))
|
||||||
if(foundModule)
|
{
|
||||||
{
|
return false;
|
||||||
return true;
|
}
|
||||||
|
if(foundModule)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// No find module. Assume the project has a CMake config file. Use
|
// No find module. Assume the project has a CMake config file. Use
|
||||||
|
@ -65,8 +65,8 @@ public:
|
|||||||
virtual const char* GetFullDocumentation()
|
virtual const char* GetFullDocumentation()
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
" FIND_PACKAGE(<name> [major.minor] [QUIET]\n"
|
" FIND_PACKAGE(<name> [major.minor] [QUIET] [NO_MODULE]\n"
|
||||||
" [REQUIRED [componets...]])\n"
|
" [[REQUIRED|COMPONENTS] [componets...]])\n"
|
||||||
"Finds and loads settings from an external project. <name>_FOUND will "
|
"Finds and loads settings from an external project. <name>_FOUND will "
|
||||||
"be set to indicate whether the package was found. Settings that "
|
"be set to indicate whether the package was found. Settings that "
|
||||||
"can be used when <name>_FOUND is true are package-specific. The "
|
"can be used when <name>_FOUND is true are package-specific. The "
|
||||||
@ -74,6 +74,7 @@ public:
|
|||||||
"Directories listed in CMAKE_MODULE_PATH are searched for files called "
|
"Directories listed in CMAKE_MODULE_PATH are searched for files called "
|
||||||
"\"Find<name>.cmake\". If such a file is found, it is read and "
|
"\"Find<name>.cmake\". If such a file is found, it is read and "
|
||||||
"processed by CMake, and is responsible for finding the package. "
|
"processed by CMake, and is responsible for finding the package. "
|
||||||
|
"This first step may be skipped by using the NO_MODULE option. "
|
||||||
"If no such file is found, it is expected that the package is another "
|
"If no such file is found, it is expected that the package is another "
|
||||||
"project built by CMake that has a \"<name>Config.cmake\" file. "
|
"project built by CMake that has a \"<name>Config.cmake\" file. "
|
||||||
"A cache entry called <name>_DIR is created and is expected to be set "
|
"A cache entry called <name>_DIR is created and is expected to be set "
|
||||||
@ -84,9 +85,10 @@ public:
|
|||||||
"argument is specified. If <name>_DIR has been set to a directory "
|
"argument is specified. If <name>_DIR has been set to a directory "
|
||||||
"not containing a \"<name>Config.cmake\" file, an error is always "
|
"not containing a \"<name>Config.cmake\" file, an error is always "
|
||||||
"generated. If REQUIRED is specified and the package is not found, "
|
"generated. If REQUIRED is specified and the package is not found, "
|
||||||
"a FATAL_ERROR is generated and the configure step stops executing."
|
"a FATAL_ERROR is generated and the configure step stops executing. "
|
||||||
" A package-specific list of components may be listed after the "
|
"A package-specific list of components may be listed after the "
|
||||||
"REQUIRED option.";
|
"REQUIRED option, or after the COMPONENTS option if no REQUIRED "
|
||||||
|
"option is given.";
|
||||||
}
|
}
|
||||||
|
|
||||||
cmTypeMacro(cmFindPackageCommand, cmCommand);
|
cmTypeMacro(cmFindPackageCommand, cmCommand);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user