summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/cmFindPackageCommand.cxx28
-rw-r--r--Source/cmFindPackageCommand.h7
2 files changed, 29 insertions, 6 deletions
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
index df2f977..75a6a26 100644
--- a/Source/cmFindPackageCommand.cxx
+++ b/Source/cmFindPackageCommand.cxx
@@ -50,6 +50,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
this->Name = args[0];
bool quiet = false;
+ bool required = false;
if(args.size() > 1)
{
cmsys::RegularExpression version("^[0-9.]+$");
@@ -64,6 +65,10 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
{
quiet = true;
}
+ else if(args[i] == "REQUIRED")
+ {
+ required = true;
+ }
else
{
cmOStringStream e;
@@ -76,7 +81,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
// See if there is a Find<name>.cmake module.
bool foundModule = false;
- if(!this->FindModule(foundModule, quiet))
+ if(!this->FindModule(foundModule, quiet, required))
{
return false;
}
@@ -155,16 +160,24 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
e << this->Variable << " is set to \"" << def << "\", which is "
<< "not a directory containing " << this->Config;
cmSystemTools::Error(e.str().c_str());
+ if(required)
+ {
+ cmSystemTools::SetFatalErrorOccured();
+ }
result = true;
}
}
- else if(!quiet)
+ else if(!quiet || required)
{
cmOStringStream e;
e << this->Variable << " is not set. It must be set to the directory "
<< "containing " << this->Config << " in order to use "
<< this->Name << ".";
cmSystemTools::Error(e.str().c_str());
+ if(required)
+ {
+ cmSystemTools::SetFatalErrorOccured();
+ }
result = true;
}
@@ -217,7 +230,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
}
//----------------------------------------------------------------------------
-bool cmFindPackageCommand::FindModule(bool& found, bool quiet)
+bool cmFindPackageCommand::FindModule(bool& found, bool quiet, bool required)
{
std::string module = "Find";
module += this->Name;
@@ -234,6 +247,15 @@ bool cmFindPackageCommand::FindModule(bool& found, bool quiet)
m_Makefile->AddDefinition(quietly.c_str(), "1");
}
+ if(required)
+ {
+ // Tell the module that is about to be read that it should report
+ // a fatal error if the package is not found.
+ std::string req = this->Name;
+ req += "_FIND_REQUIRED";
+ m_Makefile->AddDefinition(req.c_str(), "1");
+ }
+
// Load the module we found.
found = true;
return this->ReadListFile(mfile.c_str());
diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h
index 08545fa..8a90a1d 100644
--- a/Source/cmFindPackageCommand.h
+++ b/Source/cmFindPackageCommand.h
@@ -63,7 +63,7 @@ public:
virtual const char* GetFullDocumentation()
{
return
- " FIND_PACKAGE(<name> [major.minor] [QUIET])\n"
+ " FIND_PACKAGE(<name> [major.minor] [QUIET] [REQUIRED])\n"
"Finds and loads settings from an external project. <name>_FOUND will "
"be set to indicate whether the package was found. Settings that "
"can be used when <name>_FOUND is true are package-specific. The "
@@ -80,12 +80,13 @@ public:
"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.";
+ "generated. If REQUIRED is specified and the package is not found, "
+ "a FATAL_ERROR is generated and the configure step stops executing.";
}
cmTypeMacro(cmFindPackageCommand, cmCommand);
private:
- bool FindModule(bool& found, bool quiet);
+ bool FindModule(bool& found, bool quiet, bool required);
bool FindConfig();
std::string SearchForConfig() const;
bool ReadListFile(const char* f);