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 | |
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.
-rw-r--r-- | Source/cmFindPackageCommand.cxx | 28 | ||||
-rw-r--r-- | Source/cmFindPackageCommand.h | 7 |
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); |