[cmake-commits] king committed cmFindPackageCommand.cxx 1.19 1.20 cmFindPackageCommand.h 1.10 1.11

cmake-commits at cmake.org cmake-commits at cmake.org
Thu Oct 26 11:40:01 EDT 2006


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv30260

Modified Files:
	cmFindPackageCommand.cxx cmFindPackageCommand.h 
Log Message:
ENH: Added NO_MODULE and COMPONENTS options to improve flexibility of the command.  Re-implemented argument parsing to be simpler and more robust.


Index: cmFindPackageCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFindPackageCommand.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- cmFindPackageCommand.h	27 Jan 2006 18:07:23 -0000	1.10
+++ cmFindPackageCommand.h	26 Oct 2006 15:39:56 -0000	1.11
@@ -65,8 +65,8 @@
   virtual const char* GetFullDocumentation()
     {
     return
-      "  FIND_PACKAGE(<name> [major.minor] [QUIET]\n"
-      "               [REQUIRED [componets...]])\n"
+      "  FIND_PACKAGE(<name> [major.minor] [QUIET] [NO_MODULE]\n"
+      "               [[REQUIRED|COMPONENTS] [componets...]])\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 "
@@ -74,6 +74,7 @@
       "Directories listed in CMAKE_MODULE_PATH are searched for files called "
       "\"Find<name>.cmake\".  If such a file is found, it is read and "
       "processed by CMake, and is responsible for finding the package.  "
+      "This first step may be skipped by using the NO_MODULE option.  "
       "If no such file is found, it is expected that the package is another "
       "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 "
@@ -84,9 +85,10 @@
       "argument is specified.  If <name>_DIR has been set to a directory "
       "not containing a \"<name>Config.cmake\" file, an error is always "
       "generated.  If REQUIRED is specified and the package is not found, "
-      "a FATAL_ERROR is generated and the configure step stops executing."
-      "  A package-specific list of components may be listed after the "
-      "REQUIRED option.";
+      "a FATAL_ERROR is generated and the configure step stops executing.  "
+      "A package-specific list of components may be listed after the "
+      "REQUIRED option, or after the COMPONENTS option if no REQUIRED "
+      "option is given.";
     }
   
   cmTypeMacro(cmFindPackageCommand, cmCommand);

Index: cmFindPackageCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFindPackageCommand.cxx,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- cmFindPackageCommand.cxx	11 Jul 2006 21:10:00 -0000	1.19
+++ cmFindPackageCommand.cxx	26 Oct 2006 15:39:53 -0000	1.20
@@ -54,80 +54,80 @@
     return false;
     }
 
+  // Record options.
   this->Name = args[0];
-
-  // Build a list of required components.
-  std::string components;
-  const char* components_sep = "";
   bool quiet = false;
   bool required = false;
-  if(args.size() > 1)
+  bool no_module = false;
+  std::string components;
+  const char* components_sep = "";
+
+  // Parse the arguments.
+  bool doing_components = false;
+  cmsys::RegularExpression version("^[0-9.]+$");
+  bool haveVersion = false;
+  for(unsigned int i=1; i < args.size(); ++i)
     {
-    cmsys::RegularExpression version("^[0-9.]+$");
-    bool haveVersion = false;
-    for(unsigned int i=1; i < args.size(); ++i)
+    if(args[i] == "QUIET")
       {
-      if(!haveVersion && version.find(args[i].c_str()))
-        {
-        haveVersion = true;
-        }
-      else if(args[i] == "QUIET")
-        {
-        quiet = true;
-        }
-      else if(args[i] == "REQUIRED")
-        {
-        // The package is required.
-        required = true;
-
-        // Look for a list of required components.
-        while(++i < args.size())
-          {
-          // Stop looking when a known keyword argument is
-          // encountered.
-          if((args[i] == "QUIET") ||
-             (args[i] == "REQUIRED"))
-            {
-            --i;
-            break;
-            }
-          else
-            {
-            // Set a variable telling the find script this component
-            // is required.
-            std::string req_var = Name + "_FIND_REQUIRED_" + args[i];
-            this->Makefile->AddDefinition(req_var.c_str(), "1");
-
-            // Append to the list of required components.
-            components += components_sep;
-            components += args[i];
-            components_sep = ";";
-            }
-          }
-        }
-      else
-        {
-        cmOStringStream e;
-        e << "called with invalid argument \"" << args[i].c_str() << "\"";
-        this->SetError(e.str().c_str());
-        return false;
-        }
+      quiet = true;
+      doing_components = false;
+      }
+    else if(args[i] == "NO_MODULE")
+      {
+      no_module = true;
+      doing_components = false;
+      }
+    else if(args[i] == "REQUIRED")
+      {
+      required = true;
+      doing_components = true;
+      }
+    else if(args[i] == "COMPONENTS")
+      {
+      doing_components = true;
       }
+    else if(doing_components)
+      {
+      // Set a variable telling the find script this component
+      // is required.
+      std::string req_var = Name + "_FIND_REQUIRED_" + args[i];
+      this->Makefile->AddDefinition(req_var.c_str(), "1");
 
-    // Store the list of components.
-    std::string components_var = Name + "_FIND_COMPONENTS";
-    this->Makefile->AddDefinition(components_var.c_str(), components.c_str());
+      // Append to the list of required components.
+      components += components_sep;
+      components += args[i];
+      components_sep = ";";
+      }
+    else if(!haveVersion && version.find(args[i].c_str()))
+      {
+      haveVersion = true;
+      }
+    else
+      {
+      cmOStringStream e;
+      e << "called with invalid argument \"" << args[i].c_str() << "\"";
+      this->SetError(e.str().c_str());
+      return false;
+      }
     }
 
+  // Store the list of components.
+  std::string components_var = Name + "_FIND_COMPONENTS";
+  this->Makefile->AddDefinition(components_var.c_str(), components.c_str());
+
   // See if there is a Find<name>.cmake module.
-  bool foundModule = false;
-  if(!this->FindModule(foundModule, quiet, required))
-    {
-    return false;
-    }
-  if(foundModule)
+  if(!no_module)
     {
-    return true;
+    bool foundModule = false;
+    if(!this->FindModule(foundModule, quiet, required))
+      {
+      return false;
+      }
+    if(foundModule)
+      {
+      return true;
+      }
     }
 
   // No find module.  Assume the project has a CMake config file.  Use



More information about the Cmake-commits mailing list