ENH: Added QUIET optional argument to block error message when _DIR variable is not set. Also removed upper-casing of package name.

This commit is contained in:
Brad King 2003-07-16 14:52:51 -04:00
parent c2b98959c5
commit 8ca5266645
2 changed files with 36 additions and 7 deletions

View File

@ -15,6 +15,7 @@
=========================================================================*/ =========================================================================*/
#include "cmFindPackageCommand.h" #include "cmFindPackageCommand.h"
#include <cmsys/RegularExpression.hxx>
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args) bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
@ -26,7 +27,31 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
} }
this->Name = args[0]; this->Name = args[0];
this->UpperName = cmSystemTools::UpperCase(this->Name);
bool quiet = false;
if(args.size() > 1)
{
cmsys::RegularExpression version("^[0-9.]+$");
bool haveVersion = false;
for(unsigned int i=1; i < args.size(); ++i)
{
if(!haveVersion && version.find(args[i].c_str()))
{
haveVersion = true;
}
else if(args[i] == "QUIET")
{
quiet = true;
}
else
{
cmOStringStream e;
e << "called with invalid argument \"" << args[i].c_str() << "\"";
this->SetError(e.str().c_str());
return false;
}
}
}
// See if there is a Find<name>.cmake module. // See if there is a Find<name>.cmake module.
bool foundModule = false; bool foundModule = false;
@ -40,7 +65,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
} }
// No find module. Assume the project has a CMake config file. Use // No find module. Assume the project has a CMake config file. Use
// a <NAME>_DIR cache variable to locate it. // a <NAME>_DIR cache variable to locate it.
this->Variable = this->UpperName; this->Variable = this->Name;
this->Variable += "_DIR"; this->Variable += "_DIR";
this->Config = this->Name; this->Config = this->Name;
this->Config += "Config.cmake"; this->Config += "Config.cmake";
@ -82,7 +107,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
result = true; result = true;
} }
} }
else else if(!quiet)
{ {
cmOStringStream e; cmOStringStream e;
e << this->Variable << " is not set. It must be set to the directory " e << this->Variable << " is not set. It must be set to the directory "
@ -92,7 +117,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
result = true; result = true;
} }
std::string foundVar = this->UpperName; std::string foundVar = this->Name;
foundVar += "_FOUND"; foundVar += "_FOUND";
m_Makefile->AddDefinition(foundVar.c_str(), found? "1":"0"); m_Makefile->AddDefinition(foundVar.c_str(), found? "1":"0");
return result; return result;

View File

@ -64,7 +64,7 @@ public:
virtual const char* GetFullDocumentation() virtual const char* GetFullDocumentation()
{ {
return return
" FIND_PACKAGE(<name> [major.minor])\n" " FIND_PACKAGE(<name> [major.minor] [QUIET])\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 "
@ -76,7 +76,12 @@ public:
"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 "
"to the directory containing this file. If the file is found, it is " "to the directory containing this file. If the file is found, it is "
"read and processed by CMake to load the settings of the package."; "read and processed by CMake to load the settings of the package. If "
"<name>_DIR has not been set during a configure step, the command "
"will generate an error describing the problem unless the QUIET "
"argument is specified. If <name>_DIR has been set to a directory "
"not containing a \"<name>Config.cmake\" file, an error is always "
"generated.";
} }
cmTypeMacro(cmFindPackageCommand, cmCommand); cmTypeMacro(cmFindPackageCommand, cmCommand);
@ -87,7 +92,6 @@ private:
bool ReadListFile(const char* f); bool ReadListFile(const char* f);
cmStdString Name; cmStdString Name;
cmStdString UpperName;
cmStdString Variable; cmStdString Variable;
cmStdString Config; cmStdString Config;
std::vector<cmStdString> Builds; std::vector<cmStdString> Builds;