Browse Source

Rename flags again and use variablewatch for cli

Ben Boeckel 15 years ago
parent
commit
fff9f6d6f7

+ 1 - 7
Source/QtDialog/CMakeSetupDialog.cxx

@@ -121,11 +121,8 @@ CMakeSetupDialog::CMakeSetupDialog()
     OptionsMenu->addAction(tr("&Warn Uninitialized (--warn-uninitialized)"));
   this->WarnUninitializedAction->setCheckable(true);
   this->WarnUnusedAction =
-    OptionsMenu->addAction(tr("&Warn Unused (--warn-unused)"));
+    OptionsMenu->addAction(tr("&Warn Unused (--warn-unused-vars)"));
   this->WarnUnusedAction->setCheckable(true);
-  this->WarnUnusedAllAction =
-    OptionsMenu->addAction(tr("&Warn Unused All (--warn-unused-all)"));
-  this->WarnUnusedAllAction->setCheckable(true);
 
   QAction* debugAction = OptionsMenu->addAction(tr("&Debug Output"));
   debugAction->setCheckable(true);
@@ -256,9 +253,6 @@ void CMakeSetupDialog::initialize()
   QObject::connect(this->WarnUnusedAction, SIGNAL(triggered(bool)),
                    this->CMakeThread->cmakeInstance(),
                    SLOT(setWarnUnusedMode(bool)));
-  QObject::connect(this->WarnUnusedAllAction, SIGNAL(triggered(bool)),
-                   this->CMakeThread->cmakeInstance(),
-                   SLOT(setWarnUnusedAllMode(bool)));
   
   if(!this->SourceDirectory->text().isEmpty() ||
      !this->BinaryDirectory->lineEdit()->text().isEmpty())

+ 0 - 1
Source/QtDialog/CMakeSetupDialog.h

@@ -95,7 +95,6 @@ protected:
   QAction* SuppressDevWarningsAction;
   QAction* WarnUninitializedAction;
   QAction* WarnUnusedAction;
-  QAction* WarnUnusedAllAction;
   QAction* InstallForCommandLineAction;
   State CurrentState;
 

+ 0 - 7
Source/QtDialog/QCMake.cxx

@@ -30,7 +30,6 @@ QCMake::QCMake(QObject* p)
   this->SuppressDevWarnings = false;
   this->WarnUninitializedMode = false;
   this->WarnUnusedMode = false;
-  this->WarnUnusedAllMode = false;
   qRegisterMetaType<QCMakeProperty>();
   qRegisterMetaType<QCMakePropertyList>();
   
@@ -170,7 +169,6 @@ void QCMake::configure()
   std::cerr << "set warn uninitialized " << this->WarnUninitializedMode << "\n";
   this->CMakeInstance->SetWarnUninitialized(this->WarnUninitializedMode);
   this->CMakeInstance->SetWarnUnused(this->WarnUnusedMode);
-  this->CMakeInstance->SetDefaultToUsed(!this->WarnUnusedAllMode);
   this->CMakeInstance->PreLoadCMakeFiles();
 
   cmSystemTools::ResetErrorOccuredFlag();
@@ -434,8 +432,3 @@ void QCMake::setWarnUnusedMode(bool value)
 {
   this->WarnUnusedMode = value;
 }
-
-void QCMake::setWarnUnusedAllMode(bool value)
-{
-  this->WarnUnusedAllMode = value;
-}

+ 0 - 2
Source/QtDialog/QCMake.h

@@ -92,8 +92,6 @@ public slots:
   void setWarnUninitializedMode(bool value);
   /// set whether to run cmake with warnings about unused variables
   void setWarnUnusedMode(bool value);
-  /// set whether to run cmake with warnings about all unused variables
-  void setWarnUnusedAllMode(bool value);
 
 public:
   /// get the list of cache properties

+ 0 - 7
Source/cmMakefile.cxx

@@ -93,7 +93,6 @@ cmMakefile::cmMakefile(): Internal(new Internals)
   this->Initialize();
   this->PreOrder = false;
   this->WarnUnused = false;
-  this->DefaultToUsed = true;
 }
 
 cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals)
@@ -137,7 +136,6 @@ cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals)
   this->Properties = mf.Properties;
   this->PreOrder = mf.PreOrder;
   this->WarnUnused = mf.WarnUnused;
-  this->DefaultToUsed = mf.DefaultToUsed;
   this->ListFileStack = mf.ListFileStack;
   this->Initialize();
 }
@@ -767,7 +765,6 @@ void cmMakefile::SetLocalGenerator(cmLocalGenerator* lg)
     const cmDefinitions& defs = cmDefinitions();
     const std::set<cmStdString> globalKeys = defs.LocalKeys();
     this->WarnUnused = this->GetCMakeInstance()->GetWarnUnused();
-    this->DefaultToUsed = this->GetCMakeInstance()->GetDefaultToUsed();
     if (this->WarnUnused)
       {
       this->Internal->VarUsageStack.push(globalKeys);
@@ -1710,10 +1707,6 @@ void cmMakefile::AddDefinition(const char* name, bool value)
 {
   this->Internal->VarStack.top().Set(name, value? "ON" : "OFF");
   this->Internal->VarInitStack.top().insert(name);
-  if (this->WarnUnused && this->DefaultToUsed)
-    {
-    this->Internal->VarUsageStack.top().insert(name);
-    }
 #ifdef CMAKE_BUILD_WITH_CMAKE
   cmVariableWatch* vv = this->GetVariableWatch();
   if ( vv )

+ 0 - 1
Source/cmMakefile.h

@@ -935,7 +935,6 @@ private:
 
   // Unused variable flags
   bool WarnUnused;
-  bool DefaultToUsed;
 
   // stack of list files being read 
   std::deque<cmStdString> ListFileStack;

+ 36 - 7
Source/cmake.cxx

@@ -137,12 +137,19 @@ void cmNeedBackwardsCompatibility(const std::string& variable,
 #endif
 }
 
+void cmWarnUnusedCliWarning(const std::string& variable,
+  int, void* ctx, const char*, const cmMakefile*)
+{
+  cmake* cm = reinterpret_cast<cmake*>(ctx);
+  cm->MarkCliAsUsed(variable);
+}
+
 cmake::cmake()
 {
   this->Trace = false;
   this->WarnUninitialized = false;
   this->WarnUnused = false;
-  this->DefaultToUsed = true;
+  this->WarnUnusedCli = true;
   this->SuppressDevWarnings = false;
   this->DoSuppressDevWarnings = false;
   this->DebugOutput = false;
@@ -193,6 +200,19 @@ cmake::cmake()
 
 cmake::~cmake()
 {
+  if(this->WarnUnusedCli)
+    {
+    std::map<std::string, bool>::const_iterator it;
+    for(it = this->UsedCliVariables.begin(); it != this->UsedCliVariables.end(); ++it)
+      {
+      if(!it->second)
+        {
+        std::string message = "The variable, \"" + it->first + "\", given "
+          "on the command line was not used within the build.";
+        cmSystemTools::Message(message.c_str());
+        }
+      }
+    }
   delete this->CacheManager;
   delete this->Policies;
   if (this->GlobalGenerator)
@@ -370,6 +390,11 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
         {
         this->CacheManager->AddCacheEntry(var.c_str(), value.c_str(),
           "No help, variable specified on the command line.", type);
+        if(this->WarnUnusedCli)
+          {
+          this->VariableWatch->AddWatch(var, cmWarnUnusedCliWarning, this);
+          this->UsedCliVariables[var] = false;
+          }
         }
       else
         {
@@ -621,16 +646,15 @@ void cmake::SetArgs(const std::vector<std::string>& args)
       std::cout << "Warn about uninitialized values.\n";
       this->SetWarnUninitialized(true);
       }
-    else if(arg.find("--warn-unused",0) == 0)
+    else if(arg.find("--warn-unused-vars",0) == 0)
       {
-      std::cout << "Finding unused command line variables.\n";
+      std::cout << "Finding unused variables.\n";
       this->SetWarnUnused(true);
       }
-    else if(arg.find("--warn-unused-all",0) == 0)
+    else if(arg.find("--warn-unused-cli",0) == 0)
       {
-      std::cout << "Finding unused variables.\n";
-      this->SetWarnUnused(true);
-      this->SetDefaultToUsed(false);
+      std::cout << "Finding unused variables given on the command line.\n";
+      this->SetWarnUnusedCli(true);
       }
     else if(arg.find("-G",0) == 0)
       {
@@ -2836,6 +2860,11 @@ const char* cmake::GetCPackCommand()
     return this->CPackCommand.c_str();
 }
 
+void cmake::MarkCliAsUsed(const std::string& variable)
+{
+  this->UsedCliVariables[variable] = true;
+}
+
 void cmake::GenerateGraphViz(const char* fileName) const
 {
   cmGeneratedFileStream str(fileName);

+ 7 - 3
Source/cmake.h

@@ -310,8 +310,11 @@ class cmake
   void SetWarnUninitialized(bool b) {  this->WarnUninitialized = b;}
   bool GetWarnUnused() { return this->WarnUnused;}
   void SetWarnUnused(bool b) {  this->WarnUnused = b;}
-  bool GetDefaultToUsed() { return this->DefaultToUsed;}
-  void SetDefaultToUsed(bool b) {  this->DefaultToUsed = b;}
+  bool GetWarnUnusedCli() { return this->WarnUnusedCli;}
+  void SetWarnUnusedCli(bool b) {  this->WarnUnusedCli = b;}
+
+  void MarkCliAsUsed(const std::string& variable);
+
   // Define a property
   void DefineProperty(const char *name, cmProperty::ScopeType scope,
                       const char *ShortDescription,
@@ -451,7 +454,8 @@ private:
   bool Trace;
   bool WarnUninitialized;
   bool WarnUnused;
-  bool DefaultToUsed;
+  bool WarnUnusedCli;
+  std::map<std::string, bool> UsedCliVariables;
   std::string CMakeEditCommand;
   std::string CMakeCommand;
   std::string CXXEnvironment;

+ 3 - 3
Source/cmakemain.cxx

@@ -122,10 +122,10 @@ static const char * cmDocumentationOptions[][3] =
    "message(send_error ) calls."},
   {"--warn-uninitialized", "Warn about uninitialized values.",
    "Print a warning when an uninitialized variable is used."},
-  {"--warn-unused", "Warn about unused variables.",
+  {"--warn-unused-all", "Warn about unused variables.",
+   "Find variables that are declared or set, but not used."},
+  {"--warn-unused-cli", "Warn about command line options.",
    "Find variables that are declared on the command line, but not used."},
-  {"--warn-unused-all", "Warn about all unused variables.",
-   "Find variables that are declared, but not used."},
   {"--help-command cmd [file]", "Print help for a single command and exit.",
    "Full documentation specific to the given command is displayed. "
    "If a file is specified, the documentation is written into and the output "