浏览代码

Add flags to detect unused variables

Ben Boeckel 15 年之前
父节点
当前提交
d3e8eb5041
共有 3 个文件被更改,包括 24 次插入0 次删除
  1. 14 0
      Source/cmake.cxx
  2. 6 0
      Source/cmake.h
  3. 4 0
      Source/cmakemain.cxx

+ 14 - 0
Source/cmake.cxx

@@ -141,6 +141,8 @@ cmake::cmake()
 {
   this->Trace = false;
   this->StrictMode = false;
+  this->FindUnused = false;
+  this->DefaultToUsed = false;
   this->SuppressDevWarnings = false;
   this->DoSuppressDevWarnings = false;
   this->DebugOutput = false;
@@ -619,6 +621,18 @@ void cmake::SetArgs(const std::vector<std::string>& args)
       std::cout << "Running in strict mode.\n";
       this->SetStrictMode(true);
       }
+    else if(arg.find("--find-unused",0) == 0)
+      {
+      std::cout << "Finding unused command line variables.\n";
+      this->SetFindUnused(true);
+      this->SetDefaultToUsed(true);
+      }
+    else if(arg.find("--find-unused-all",0) == 0)
+      {
+      std::cout << "Finding unused variables.\n";
+      this->SetFindUnused(true);
+      this->SetDefaultToUsed(false);
+      }
     else if(arg.find("-G",0) == 0)
       {
       std::string value = arg.substr(2);

+ 6 - 0
Source/cmake.h

@@ -308,6 +308,10 @@ class cmake
   void SetTrace(bool b) {  this->Trace = b;}
   bool GetStrictMode() { return this->StrictMode;}
   void SetStrictMode(bool b) {  this->StrictMode = b;}
+  bool GetFindUnused() { return this->FindUnused;}
+  void SetFindUnused(bool b) {  this->FindUnused = b;}
+  bool GetDefaultToUsed() { return this->DefaultToUsed;}
+  void SetDefaultToUsed(bool b) {  this->DefaultToUsed = b;}
   // Define a property
   void DefineProperty(const char *name, cmProperty::ScopeType scope,
                       const char *ShortDescription,
@@ -446,6 +450,8 @@ private:
   bool DebugOutput;
   bool Trace;
   bool StrictMode;
+  bool FindUnused;
+  bool DefaultToUsed;
   std::string CMakeEditCommand;
   std::string CMakeCommand;
   std::string CXXEnvironment;

+ 4 - 0
Source/cmakemain.cxx

@@ -123,6 +123,10 @@ static const char * cmDocumentationOptions[][3] =
   {"--strict-mode", "Put cmake in strict mode.",
    "In strict mode cmake will print a warning when an uninitialized variable "
    "is used."},
+  {"--find-unused", "Find unused variables.",
+   "Find variables that are declared on the command line, but not used."},
+  {"--find-unused-all", "Find 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 "