From 8ca5266645c5fa3d65728508a8eb3c6ebe30c1f6 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 16 Jul 2003 14:52:51 -0400 Subject: [PATCH] ENH: Added QUIET optional argument to block error message when _DIR variable is not set. Also removed upper-casing of package name. --- Source/cmFindPackageCommand.cxx | 33 +++++++++++++++++++++++++++++---- Source/cmFindPackageCommand.h | 10 +++++++--- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 5dd2eb3b7..88819299d 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -15,6 +15,7 @@ =========================================================================*/ #include "cmFindPackageCommand.h" +#include //---------------------------------------------------------------------------- bool cmFindPackageCommand::InitialPass(std::vector const& args) @@ -26,7 +27,31 @@ bool cmFindPackageCommand::InitialPass(std::vector const& args) } 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.cmake module. bool foundModule = false; @@ -40,7 +65,7 @@ bool cmFindPackageCommand::InitialPass(std::vector const& args) } // No find module. Assume the project has a CMake config file. Use // a _DIR cache variable to locate it. - this->Variable = this->UpperName; + this->Variable = this->Name; this->Variable += "_DIR"; this->Config = this->Name; this->Config += "Config.cmake"; @@ -82,7 +107,7 @@ bool cmFindPackageCommand::InitialPass(std::vector const& args) result = true; } } - else + else if(!quiet) { cmOStringStream e; e << this->Variable << " is not set. It must be set to the directory " @@ -92,7 +117,7 @@ bool cmFindPackageCommand::InitialPass(std::vector const& args) result = true; } - std::string foundVar = this->UpperName; + std::string foundVar = this->Name; foundVar += "_FOUND"; m_Makefile->AddDefinition(foundVar.c_str(), found? "1":"0"); return result; diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h index 73cb4a32f..f559ee9fe 100644 --- a/Source/cmFindPackageCommand.h +++ b/Source/cmFindPackageCommand.h @@ -64,7 +64,7 @@ public: virtual const char* GetFullDocumentation() { return - " FIND_PACKAGE( [major.minor])\n" + " FIND_PACKAGE( [major.minor] [QUIET])\n" "Finds and loads settings from an external project. _FOUND will " "be set to indicate whether the package was found. Settings that " "can be used when _FOUND is true are package-specific. The " @@ -76,7 +76,12 @@ public: "project built by CMake that has a \"Config.cmake\" file. " "A cache entry called _DIR is created and is expected to be set " "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 " + "_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 _DIR has been set to a directory " + "not containing a \"Config.cmake\" file, an error is always " + "generated."; } cmTypeMacro(cmFindPackageCommand, cmCommand); @@ -87,7 +92,6 @@ private: bool ReadListFile(const char* f); cmStdString Name; - cmStdString UpperName; cmStdString Variable; cmStdString Config; std::vector Builds;