diff options
author | Brad King <brad.king@kitware.com> | 2004-04-19 14:36:42 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2004-04-19 14:36:42 (GMT) |
commit | d4214bc5659e3f80b530b9e253525ae156618cb5 (patch) | |
tree | f1490d78078323bdfc9df60d36e763f2f67b9b64 /Source/cmFindPackageCommand.cxx | |
parent | 55a71ba572c54dbb3485a76e9615c1c8bf688fd4 (diff) | |
download | CMake-d4214bc5659e3f80b530b9e253525ae156618cb5.zip CMake-d4214bc5659e3f80b530b9e253525ae156618cb5.tar.gz CMake-d4214bc5659e3f80b530b9e253525ae156618cb5.tar.bz2 |
ENH#696: Adding REQUIRED option to FIND_PACKAGE command. It will terminate the cmake configure step if the package is not found.
Diffstat (limited to 'Source/cmFindPackageCommand.cxx')
-rw-r--r-- | Source/cmFindPackageCommand.cxx | 28 |
1 files changed, 25 insertions, 3 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()); |