Преглед на файлове

find_package: Reject mixed use of MODULE- and CONFIG-only options

Many options imply exclusive Config mode.  The new MODULE option
implies exclusive Module mode.  Do not allow mixed combinations.
Brad King преди 13 години
родител
ревизия
31ead5f695
променени са 1 файла, в които са добавени 37 реда и са изтрити 43 реда
  1. 37 43
      Source/cmFindPackageCommand.cxx

+ 37 - 43
Source/cmFindPackageCommand.cxx

@@ -415,7 +415,8 @@ bool cmFindPackageCommand
   Doing doing = DoingNone;
   Doing doing = DoingNone;
   cmsys::RegularExpression version("^[0-9.]+$");
   cmsys::RegularExpression version("^[0-9.]+$");
   bool haveVersion = false;
   bool haveVersion = false;
-  std::string haveModeString = "";
+  std::set<unsigned int> configArgs;
+  std::set<unsigned int> moduleArgs;
   for(unsigned int i=1; i < args.size(); ++i)
   for(unsigned int i=1; i < args.size(); ++i)
     {
     {
     if(args[i] == "QUIET")
     if(args[i] == "QUIET")
@@ -431,48 +432,18 @@ bool cmFindPackageCommand
       }
       }
     else if(args[i] == "MODULE")
     else if(args[i] == "MODULE")
       {
       {
-      if(!haveModeString.empty())
-        {
-        cmOStringStream e;
-        e << "given " << args[i] << ", but mode is already set to "
-          << haveModeString << ".";
-        this->SetError(e.str().c_str());
-        return false;
-        }
-
-      this->UseConfigFiles = false;
+      moduleArgs.insert(i);
       doing = DoingNone;
       doing = DoingNone;
-      haveModeString = args[i];
       }
       }
     else if(args[i] == "CONFIG")
     else if(args[i] == "CONFIG")
       {
       {
-      if(!haveModeString.empty())
-        {
-        cmOStringStream e;
-        e << "given " << args[i] << ", but mode is already set to "
-          << haveModeString << ".";
-        this->SetError(e.str().c_str());
-        return false;
-        }
-
-      this->UseFindModules = false;
+      configArgs.insert(i);
       doing = DoingNone;
       doing = DoingNone;
-      haveModeString = args[i];
       }
       }
     else if(args[i] == "NO_MODULE")
     else if(args[i] == "NO_MODULE")
       {
       {
-      if(!haveModeString.empty())
-        {
-        cmOStringStream e;
-        e << "given " << args[i] << ", but mode is already set to "
-          << haveModeString << ".";
-        this->SetError(e.str().c_str());
-        return false;
-        }
-
-      this->UseFindModules = false;
+      configArgs.insert(i);
       doing = DoingNone;
       doing = DoingNone;
-      haveModeString = args[i];
       }
       }
     else if(args[i] == "REQUIRED")
     else if(args[i] == "REQUIRED")
       {
       {
@@ -486,31 +457,31 @@ bool cmFindPackageCommand
       }
       }
     else if(args[i] == "NAMES")
     else if(args[i] == "NAMES")
       {
       {
-      this->UseFindModules = false;
+      configArgs.insert(i);
       this->Compatibility_1_6 = false;
       this->Compatibility_1_6 = false;
       doing = DoingNames;
       doing = DoingNames;
       }
       }
     else if(args[i] == "PATHS")
     else if(args[i] == "PATHS")
       {
       {
-      this->UseFindModules = false;
+      configArgs.insert(i);
       this->Compatibility_1_6 = false;
       this->Compatibility_1_6 = false;
       doing = DoingPaths;
       doing = DoingPaths;
       }
       }
     else if(args[i] == "HINTS")
     else if(args[i] == "HINTS")
       {
       {
-      this->UseFindModules = false;
+      configArgs.insert(i);
       this->Compatibility_1_6 = false;
       this->Compatibility_1_6 = false;
       doing = DoingHints;
       doing = DoingHints;
       }
       }
     else if(args[i] == "PATH_SUFFIXES")
     else if(args[i] == "PATH_SUFFIXES")
       {
       {
-      this->UseFindModules = false;
+      configArgs.insert(i);
       this->Compatibility_1_6 = false;
       this->Compatibility_1_6 = false;
       doing = DoingPathSuffixes;
       doing = DoingPathSuffixes;
       }
       }
     else if(args[i] == "CONFIGS")
     else if(args[i] == "CONFIGS")
       {
       {
-      this->UseFindModules = false;
+      configArgs.insert(i);
       this->Compatibility_1_6 = false;
       this->Compatibility_1_6 = false;
       doing = DoingConfigs;
       doing = DoingConfigs;
       }
       }
@@ -523,27 +494,27 @@ bool cmFindPackageCommand
     else if(args[i] == "NO_CMAKE_PACKAGE_REGISTRY")
     else if(args[i] == "NO_CMAKE_PACKAGE_REGISTRY")
       {
       {
       this->NoUserRegistry = true;
       this->NoUserRegistry = true;
-      this->UseFindModules = false;
+      configArgs.insert(i);
       this->Compatibility_1_6 = false;
       this->Compatibility_1_6 = false;
       doing = DoingNone;
       doing = DoingNone;
       }
       }
     else if(args[i] == "NO_CMAKE_SYSTEM_PACKAGE_REGISTRY")
     else if(args[i] == "NO_CMAKE_SYSTEM_PACKAGE_REGISTRY")
       {
       {
       this->NoSystemRegistry = true;
       this->NoSystemRegistry = true;
-      this->UseFindModules = false;
+      configArgs.insert(i);
       this->Compatibility_1_6 = false;
       this->Compatibility_1_6 = false;
       doing = DoingNone;
       doing = DoingNone;
       }
       }
     else if(args[i] == "NO_CMAKE_BUILDS_PATH")
     else if(args[i] == "NO_CMAKE_BUILDS_PATH")
       {
       {
       this->NoBuilds = true;
       this->NoBuilds = true;
-      this->UseFindModules = false;
+      configArgs.insert(i);
       this->Compatibility_1_6 = false;
       this->Compatibility_1_6 = false;
       doing = DoingNone;
       doing = DoingNone;
       }
       }
     else if(this->CheckCommonArgument(args[i]))
     else if(this->CheckCommonArgument(args[i]))
       {
       {
-      this->UseFindModules = false;
+      configArgs.insert(i);
       this->Compatibility_1_6 = false;
       this->Compatibility_1_6 = false;
       doing = DoingNone;
       doing = DoingNone;
       }
       }
@@ -603,6 +574,29 @@ bool cmFindPackageCommand
       }
       }
     }
     }
 
 
+  // Maybe choose one mode exclusively.
+  this->UseFindModules = configArgs.empty();
+  this->UseConfigFiles = moduleArgs.empty();
+  if(!this->UseFindModules && !this->UseConfigFiles)
+    {
+    cmOStringStream e;
+    e << "given options exclusive to Module mode:\n";
+    for(std::set<unsigned int>::const_iterator si = moduleArgs.begin();
+        si != moduleArgs.end(); ++si)
+      {
+      e << "  " << args[*si] << "\n";
+      }
+    e << "and options exclusive to Config mode:\n";
+    for(std::set<unsigned int>::const_iterator si = configArgs.begin();
+        si != configArgs.end(); ++si)
+      {
+      e << "  " << args[*si] << "\n";
+      }
+    e << "The options are incompatible.";
+    this->SetError(e.str().c_str());
+    return false;
+    }
+
   // Ignore EXACT with no version.
   // Ignore EXACT with no version.
   if(this->Version.empty() && this->VersionExact)
   if(this->Version.empty() && this->VersionExact)
     {
     {