[Cmake-commits] CMake branch, next, updated. v2.8.2-804-gbab72e1

Ben Boeckel ben.boeckel at kitware.com
Thu Sep 16 11:58:00 EDT 2010


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  bab72e1b6d70d09aecb101b52f69ef595459a50e (commit)
       via  59463ef1a33a22113e1c577c450d7b2c70916bbc (commit)
       via  f117423336a91f4f50f031d0acc892d4c10316c3 (commit)
       via  e49a935c20550482e9f92ceb05d1f2a0bc519c91 (commit)
       via  e01e40cb87f464dd5b1d5ca1c8f0884f573c1b72 (commit)
       via  a17aff74c7a571657414a0b82e431bbefbbb857b (commit)
       via  02a114dfe8304e6fa90b9c6565349eb7e0fb1168 (commit)
       via  a0b0d23f0cc3f596135ace5d675bbb09911b7f02 (commit)
       via  ae3eff35b4814334f3a7e5f3240911aad0936c84 (commit)
       via  056b44113f86a79ea9d68548005292a9d48d45f8 (commit)
       via  980e048a7d5356a881dbaaf25b1595091fe5cb8b (commit)
      from  831321f083e651436994009b9c35f6f47f3f4a00 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=bab72e1b6d70d09aecb101b52f69ef595459a50e
commit bab72e1b6d70d09aecb101b52f69ef595459a50e
Merge: 831321f 59463ef
Author:     Ben Boeckel <ben.boeckel at kitware.com>
AuthorDate: Thu Sep 16 11:57:48 2010 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Thu Sep 16 11:57:48 2010 -0400

    Merge topic 'dev/strict-mode' into next
    
    59463ef Rework CheckVariableForUnused usage
    f117423 Fix line lengths to be no more than 78
    e49a935 Improve unused warning logic
    e01e40c Mark ARGC, ARGV*, and ARGN as used
    a17aff7 Ignore CMAKE_MATCH_* variables for usage
    02a114d Add method to allow variables to be marked as used
    a0b0d23 CMAKE_DO_TRY_COMPILE is no longer used
    ae3eff3 Fix the path used for ignoring system warnings
    056b441 Fix missing case for usage of a variable
    980e048 Factor out checks for unused variables


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=59463ef1a33a22113e1c577c450d7b2c70916bbc
commit 59463ef1a33a22113e1c577c450d7b2c70916bbc
Author:     Ben Boeckel <ben.boeckel at kitware.com>
AuthorDate: Thu Sep 16 11:50:57 2010 -0400
Commit:     Ben Boeckel <ben.boeckel at kitware.com>
CommitDate: Thu Sep 16 11:50:57 2010 -0400

    Rework CheckVariableForUnused usage

diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 592e05e..df871ec 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -1771,7 +1771,7 @@ bool cmMakefile::VariableCleared(const char* var) const
   return false;
 }
 
-bool cmMakefile::CheckForUnused(const char* reason, const char* name)
+void cmMakefile::CheckForUnused(const char* reason, const char* name) const
 {
   if (this->WarnUnused && !this->VariableUsed(name))
     {
@@ -1786,10 +1786,8 @@ bool cmMakefile::CheckForUnused(const char* reason, const char* name)
       msg << file->FilePath << ":" << file->Line << ":" <<
         " warning: (" << reason << ") unused variable \'" << name << "\'";
       cmSystemTools::Message(msg.str().c_str());
-      return true;
       }
     }
-  return false;
 }
 
 void cmMakefile::RemoveDefinition(const char* name)
@@ -3429,7 +3427,11 @@ void cmMakefile::PopScope()
   for (; it != locals.end(); ++it)
     {
     init.erase(*it);
-    if (!this->CheckForUnused("out of scope", it->c_str()))
+    if (!this->VariableUsed(it->c_str()))
+      {
+      this->CheckForUnused("out of scope", it->c_str());
+      }
+    else
       {
       usage.erase(*it);
       }
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index 6b0bfa2..7826903 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -844,7 +844,7 @@ protected:
   void AddGlobalLinkInformation(const char* name, cmTarget& target);
 
   // Check for a an unused variable
-  bool CheckForUnused(const char* reason, const char* name);
+  void CheckForUnused(const char* reason, const char* name) const;
 
   std::string Prefix;
   std::vector<std::string> AuxSourceDirectories; // 

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f117423336a91f4f50f031d0acc892d4c10316c3
commit f117423336a91f4f50f031d0acc892d4c10316c3
Author:     Ben Boeckel <ben.boeckel at kitware.com>
AuthorDate: Thu Sep 16 11:49:58 2010 -0400
Commit:     Ben Boeckel <ben.boeckel at kitware.com>
CommitDate: Thu Sep 16 11:49:58 2010 -0400

    Fix line lengths to be no more than 78

diff --git a/Source/cmCommandArgumentParserHelper.cxx b/Source/cmCommandArgumentParserHelper.cxx
index 8b009e0..3f1ba53 100644
--- a/Source/cmCommandArgumentParserHelper.cxx
+++ b/Source/cmCommandArgumentParserHelper.cxx
@@ -131,8 +131,10 @@ char* cmCommandArgumentParserHelper::ExpandVariable(const char* var)
     if(this->WarnUninitialized && !this->Makefile->VariableInitialized(var))
       {
       if (this->CheckSystemVars ||
-          cmSystemTools::IsSubDirectory(this->FileName, this->Makefile->GetHomeDirectory()) ||
-          cmSystemTools::IsSubDirectory(this->FileName, this->Makefile->GetHomeOutputDirectory()))
+          cmSystemTools::IsSubDirectory(this->FileName,
+                                        this->Makefile->GetHomeDirectory()) ||
+          cmSystemTools::IsSubDirectory(this->FileName,
+                                        this->Makefile->GetHomeOutputDirectory()))
         {
         cmOStringStream msg;
         msg << this->FileName << ":" << this->FileLine << ":" <<
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 9d5c59e..592e05e 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -1649,7 +1649,8 @@ void cmMakefile::AddDefinition(const char* name, const char* value)
 #endif
 
   this->Internal->VarStack.top().Set(name, value);
-  if ((this->Internal->VarUsageStack.size() > 1) && this->VariableInitialized(name))
+  if ((this->Internal->VarUsageStack.size() > 1) &&
+      this->VariableInitialized(name))
     {
     this->CheckForUnused("changing definition", name);
     this->Internal->VarUsageStack.top().erase(name);
@@ -1719,7 +1720,8 @@ void cmMakefile::AddCacheDefinition(const char* name, const char* value,
 void cmMakefile::AddDefinition(const char* name, bool value)
 {
   this->Internal->VarStack.top().Set(name, value? "ON" : "OFF");
-  if ((this->Internal->VarUsageStack.size() > 1) && this->VariableInitialized(name))
+  if ((this->Internal->VarUsageStack.size() > 1) &&
+      this->VariableInitialized(name))
     {
     this->CheckForUnused("changing definition", name);
     this->Internal->VarUsageStack.top().erase(name);
@@ -1742,7 +1744,8 @@ void cmMakefile::MarkVariableAsUsed(const char* var)
 
 bool cmMakefile::VariableInitialized(const char* var) const
 {
-  if(this->Internal->VarInitStack.top().find(var) != this->Internal->VarInitStack.top().end())
+  if(this->Internal->VarInitStack.top().find(var) !=
+      this->Internal->VarInitStack.top().end())
     {
     return true;
     }
@@ -1751,7 +1754,8 @@ bool cmMakefile::VariableInitialized(const char* var) const
 
 bool cmMakefile::VariableUsed(const char* var) const
 {
-  if(this->Internal->VarUsageStack.top().find(var) != this->Internal->VarUsageStack.top().end())
+  if(this->Internal->VarUsageStack.top().find(var) !=
+      this->Internal->VarUsageStack.top().end())
     {
     return true;
     }
@@ -1773,8 +1777,10 @@ bool cmMakefile::CheckForUnused(const char* reason, const char* name)
     {
     const cmListFileContext* file = this->CallStack.back().Context;
     if (this->CheckSystemVars ||
-        cmSystemTools::IsSubDirectory(file->FilePath.c_str(), this->GetHomeDirectory()) ||
-        cmSystemTools::IsSubDirectory(file->FilePath.c_str(), this->GetHomeOutputDirectory()))
+        cmSystemTools::IsSubDirectory(file->FilePath.c_str(),
+                                      this->GetHomeDirectory()) ||
+        cmSystemTools::IsSubDirectory(file->FilePath.c_str(),
+                                      this->GetHomeOutputDirectory()))
       {
       cmOStringStream msg;
       msg << file->FilePath << ":" << file->Line << ":" <<
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 757ad6f..007f52d 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -643,12 +643,14 @@ void cmake::SetArgs(const std::vector<std::string>& args)
       }
     else if(arg.find("--no-warn-unused-cli",0) == 0)
       {
-      std::cout << "Not finding unused variables given on the command line.\n";
+      std::cout << "Not searching for unused variables given on the " <<
+                   "command line.\n";
       this->SetWarnUnusedCli(false);
       }
     else if(arg.find("--check-system-vars",0) == 0)
       {
-      std::cout << "Also check system files when warning about unused and uninitialized variables.\n";
+      std::cout << "Also check system files when warning about unused and " <<
+                   "uninitialized variables.\n";
       this->SetCheckSystemVars(true);
       }
     else if(arg.find("-G",0) == 0)
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx
index aa455a0..a51673c 100644
--- a/Source/cmakemain.cxx
+++ b/Source/cmakemain.cxx
@@ -125,10 +125,12 @@ static const char * cmDocumentationOptions[][3] =
   {"--warn-unused-vars", "Warn about unused variables.",
    "Find variables that are declared or set, but not used."},
   {"--no-warn-unused-cli", "Don't warn about command line options.",
-   "Don't find variables that are declared on the command line, but not used."},
-  {"--check-system-vars", "Find problems with variable usage in system files.",
-   "Normally, unused and uninitialized variables are searched for only in CMAKE_SOURCE_DIR "
-   "and CMAKE_BINARY_DIR. This flag tells CMake to warn about other files as well."},
+   "Don't find variables that are declared on the command line, but not "
+   "used."},
+  {"--check-system-vars", "Find problems with variable usage in system "
+   "files.", "Normally, unused and uninitialized variables are searched for "
+   "only in CMAKE_SOURCE_DIR and CMAKE_BINARY_DIR. This flag tells CMake to "
+   "warn about other files as well."},
   {"--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 "

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e49a935c20550482e9f92ceb05d1f2a0bc519c91
commit e49a935c20550482e9f92ceb05d1f2a0bc519c91
Author:     Ben Boeckel <ben.boeckel at kitware.com>
AuthorDate: Wed Sep 15 11:41:27 2010 -0400
Commit:     Ben Boeckel <ben.boeckel at kitware.com>
CommitDate: Wed Sep 15 11:41:27 2010 -0400

    Improve unused warning logic
    
    Only warn when changing the definition of an initialized variable.

diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 85a0ccc..9d5c59e 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -1649,12 +1649,12 @@ void cmMakefile::AddDefinition(const char* name, const char* value)
 #endif
 
   this->Internal->VarStack.top().Set(name, value);
-  this->Internal->VarInitStack.top().insert(name);
-  if (this->Internal->VarUsageStack.size() > 1)
+  if ((this->Internal->VarUsageStack.size() > 1) && this->VariableInitialized(name))
     {
     this->CheckForUnused("changing definition", name);
     this->Internal->VarUsageStack.top().erase(name);
     }
+  this->Internal->VarInitStack.top().insert(name);
 
 #ifdef CMAKE_BUILD_WITH_CMAKE
   cmVariableWatch* vv = this->GetVariableWatch();
@@ -1719,12 +1719,12 @@ void cmMakefile::AddCacheDefinition(const char* name, const char* value,
 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->Internal->VarUsageStack.size() > 1)
+  if ((this->Internal->VarUsageStack.size() > 1) && this->VariableInitialized(name))
     {
     this->CheckForUnused("changing definition", name);
     this->Internal->VarUsageStack.top().erase(name);
     }
+  this->Internal->VarInitStack.top().insert(name);
 #ifdef CMAKE_BUILD_WITH_CMAKE
   cmVariableWatch* vv = this->GetVariableWatch();
   if ( vv )

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e01e40cb87f464dd5b1d5ca1c8f0884f573c1b72
commit e01e40cb87f464dd5b1d5ca1c8f0884f573c1b72
Author:     Ben Boeckel <ben.boeckel at kitware.com>
AuthorDate: Wed Sep 15 11:35:50 2010 -0400
Commit:     Ben Boeckel <ben.boeckel at kitware.com>
CommitDate: Wed Sep 15 11:35:50 2010 -0400

    Mark ARGC, ARGV*, and ARGN as used

diff --git a/Source/cmFunctionCommand.cxx b/Source/cmFunctionCommand.cxx
index b05642e..b226574 100644
--- a/Source/cmFunctionCommand.cxx
+++ b/Source/cmFunctionCommand.cxx
@@ -112,15 +112,19 @@ bool cmFunctionHelperCommand::InvokeInitialPass
   // set the value of argc
   cmOStringStream strStream;
   strStream << expandedArgs.size();
+  this->Makefile->MarkVariableAsUsed("ARGC");
   this->Makefile->AddDefinition("ARGC",strStream.str().c_str());
+  this->Makefile->MarkVariableAsUsed("ARGC");
 
   // set the values for ARGV0 ARGV1 ...
   for (unsigned int t = 0; t < expandedArgs.size(); ++t)
     {
     cmOStringStream tmpStream;
     tmpStream << "ARGV" << t;
+    this->Makefile->MarkVariableAsUsed(tmpStream.str().c_str());
     this->Makefile->AddDefinition(tmpStream.str().c_str(), 
                                   expandedArgs[t].c_str());
+    this->Makefile->MarkVariableAsUsed(tmpStream.str().c_str());
     }
   
   // define the formal arguments
@@ -152,8 +156,12 @@ bool cmFunctionHelperCommand::InvokeInitialPass
       }
     cnt ++;
     }
+  this->Makefile->MarkVariableAsUsed("ARGV");
   this->Makefile->AddDefinition("ARGV", argvDef.c_str());
+  this->Makefile->MarkVariableAsUsed("ARGV");
+  this->Makefile->MarkVariableAsUsed("ARGN");
   this->Makefile->AddDefinition("ARGN", argnDef.c_str());
+  this->Makefile->MarkVariableAsUsed("ARGN");
 
   // Invoke all the functions that were collected in the block.
   // for each function

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a17aff74c7a571657414a0b82e431bbefbbb857b
commit a17aff74c7a571657414a0b82e431bbefbbb857b
Author:     Ben Boeckel <ben.boeckel at kitware.com>
AuthorDate: Wed Sep 15 11:35:05 2010 -0400
Commit:     Ben Boeckel <ben.boeckel at kitware.com>
CommitDate: Wed Sep 15 11:35:05 2010 -0400

    Ignore CMAKE_MATCH_* variables for usage

diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx
index 19f5c0f..bab08fe 100644
--- a/Source/cmStringCommand.cxx
+++ b/Source/cmStringCommand.cxx
@@ -482,6 +482,7 @@ void cmStringCommand::ClearMatches(cmMakefile* mf)
     char name[128];
     sprintf(name, "CMAKE_MATCH_%d", i);
     mf->AddDefinition(name, "");
+    mf->MarkVariableAsUsed(name);
     }
 }
 
@@ -493,6 +494,7 @@ void cmStringCommand::StoreMatches(cmMakefile* mf,cmsys::RegularExpression& re)
     char name[128];
     sprintf(name, "CMAKE_MATCH_%d", i);
     mf->AddDefinition(name, re.match(i).c_str());
+    mf->MarkVariableAsUsed(name);
     }
 }
 

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=02a114dfe8304e6fa90b9c6565349eb7e0fb1168
commit 02a114dfe8304e6fa90b9c6565349eb7e0fb1168
Author:     Ben Boeckel <ben.boeckel at kitware.com>
AuthorDate: Wed Sep 15 11:34:35 2010 -0400
Commit:     Ben Boeckel <ben.boeckel at kitware.com>
CommitDate: Wed Sep 15 11:34:35 2010 -0400

    Add method to allow variables to be marked as used

diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 4084d0e..85a0ccc 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -1735,6 +1735,11 @@ void cmMakefile::AddDefinition(const char* name, bool value)
 #endif
 }
 
+void cmMakefile::MarkVariableAsUsed(const char* var)
+{
+  this->Internal->VarUsageStack.top().insert(var);
+}
+
 bool cmMakefile::VariableInitialized(const char* var) const
 {
   if(this->Internal->VarInitStack.top().find(var) != this->Internal->VarInitStack.top().end())
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index 89979d6..6b0bfa2 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -61,6 +61,8 @@ public:
   unsigned int GetCacheMajorVersion();
   unsigned int GetCacheMinorVersion();
 
+  /* Mark a variable as used */
+  void MarkVariableAsUsed(const char* var);
   /* return true if a variable has been initialized */
   bool VariableInitialized(const char* ) const;
   /* return true if a variable has been used */

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a0b0d23f0cc3f596135ace5d675bbb09911b7f02
commit a0b0d23f0cc3f596135ace5d675bbb09911b7f02
Author:     Ben Boeckel <ben.boeckel at kitware.com>
AuthorDate: Tue Sep 14 17:51:43 2010 -0400
Commit:     Ben Boeckel <ben.boeckel at kitware.com>
CommitDate: Tue Sep 14 17:51:43 2010 -0400

    CMAKE_DO_TRY_COMPILE is no longer used

diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
index b8a0c95..30356c8 100644
--- a/Source/cmCoreTryCompile.cxx
+++ b/Source/cmCoreTryCompile.cxx
@@ -245,10 +245,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
       CMAKE_TRY_COMPILE_OSX_ARCHITECTURE first to i386 and then to ppc to
       have the tests run for each specific architecture. Since 
       cmLocalGenerator doesn't allow building for "the other" 
-      architecture only via CMAKE_OSX_ARCHITECTURES,use to CMAKE_DO_TRY_COMPILE
-      to enforce it for this case here.
+      architecture only via CMAKE_OSX_ARCHITECTURES.
       */
-    cmakeFlags.push_back("-DCMAKE_DO_TRY_COMPILE=TRUE");
     if(this->Makefile->GetDefinition("CMAKE_TRY_COMPILE_OSX_ARCHITECTURES")!=0)
       {
       std::string flag="-DCMAKE_OSX_ARCHITECTURES=";

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ae3eff35b4814334f3a7e5f3240911aad0936c84
commit ae3eff35b4814334f3a7e5f3240911aad0936c84
Author:     Ben Boeckel <ben.boeckel at kitware.com>
AuthorDate: Tue Sep 14 17:14:25 2010 -0400
Commit:     Ben Boeckel <ben.boeckel at kitware.com>
CommitDate: Tue Sep 14 17:14:25 2010 -0400

    Fix the path used for ignoring system warnings

diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index f6c8c73..4084d0e 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -1766,13 +1766,12 @@ bool cmMakefile::CheckForUnused(const char* reason, const char* name)
 {
   if (this->WarnUnused && !this->VariableUsed(name))
     {
-    const char* cdir = this->ListFileStack.back().c_str();
+    const cmListFileContext* file = this->CallStack.back().Context;
     if (this->CheckSystemVars ||
-        cmSystemTools::IsSubDirectory(cdir, this->GetHomeDirectory()) ||
-        cmSystemTools::IsSubDirectory(cdir, this->GetHomeOutputDirectory()))
+        cmSystemTools::IsSubDirectory(file->FilePath.c_str(), this->GetHomeDirectory()) ||
+        cmSystemTools::IsSubDirectory(file->FilePath.c_str(), this->GetHomeOutputDirectory()))
       {
       cmOStringStream msg;
-      const cmListFileContext* file = this->CallStack.back().Context;
       msg << file->FilePath << ":" << file->Line << ":" <<
         " warning: (" << reason << ") unused variable \'" << name << "\'";
       cmSystemTools::Message(msg.str().c_str());

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=056b44113f86a79ea9d68548005292a9d48d45f8
commit 056b44113f86a79ea9d68548005292a9d48d45f8
Author:     Ben Boeckel <ben.boeckel at kitware.com>
AuthorDate: Tue Sep 14 17:10:22 2010 -0400
Commit:     Ben Boeckel <ben.boeckel at kitware.com>
CommitDate: Tue Sep 14 17:10:22 2010 -0400

    Fix missing case for usage of a variable

diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index c174bd6..f6c8c73 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -1649,6 +1649,7 @@ void cmMakefile::AddDefinition(const char* name, const char* value)
 #endif
 
   this->Internal->VarStack.top().Set(name, value);
+  this->Internal->VarInitStack.top().insert(name);
   if (this->Internal->VarUsageStack.size() > 1)
     {
     this->CheckForUnused("changing definition", name);

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=980e048a7d5356a881dbaaf25b1595091fe5cb8b
commit 980e048a7d5356a881dbaaf25b1595091fe5cb8b
Author:     Ben Boeckel <ben.boeckel at kitware.com>
AuthorDate: Tue Sep 14 15:22:31 2010 -0400
Commit:     Ben Boeckel <ben.boeckel at kitware.com>
CommitDate: Tue Sep 14 17:10:04 2010 -0400

    Factor out checks for unused variables

diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index c15f5b3..c174bd6 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -1649,6 +1649,11 @@ void cmMakefile::AddDefinition(const char* name, const char* value)
 #endif
 
   this->Internal->VarStack.top().Set(name, value);
+  if (this->Internal->VarUsageStack.size() > 1)
+    {
+    this->CheckForUnused("changing definition", name);
+    this->Internal->VarUsageStack.top().erase(name);
+    }
 
 #ifdef CMAKE_BUILD_WITH_CMAKE
   cmVariableWatch* vv = this->GetVariableWatch();
@@ -1714,6 +1719,11 @@ 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->Internal->VarUsageStack.size() > 1)
+    {
+    this->CheckForUnused("changing definition", name);
+    this->Internal->VarUsageStack.top().erase(name);
+    }
 #ifdef CMAKE_BUILD_WITH_CMAKE
   cmVariableWatch* vv = this->GetVariableWatch();
   if ( vv )
@@ -1751,15 +1761,32 @@ bool cmMakefile::VariableCleared(const char* var) const
   return false;
 }
 
+bool cmMakefile::CheckForUnused(const char* reason, const char* name)
+{
+  if (this->WarnUnused && !this->VariableUsed(name))
+    {
+    const char* cdir = this->ListFileStack.back().c_str();
+    if (this->CheckSystemVars ||
+        cmSystemTools::IsSubDirectory(cdir, this->GetHomeDirectory()) ||
+        cmSystemTools::IsSubDirectory(cdir, this->GetHomeOutputDirectory()))
+      {
+      cmOStringStream msg;
+      const cmListFileContext* file = this->CallStack.back().Context;
+      msg << file->FilePath << ":" << file->Line << ":" <<
+        " warning: (" << reason << ") unused variable \'" << name << "\'";
+      cmSystemTools::Message(msg.str().c_str());
+      return true;
+      }
+    }
+  return false;
+}
+
 void cmMakefile::RemoveDefinition(const char* name)
 {
   this->Internal->VarStack.top().Set(name, 0);
   this->Internal->VarRemoved.insert(name);
   this->Internal->VarInitStack.top().insert(name);
-  if (this->WarnUnused)
-    {
-    this->Internal->VarUsageStack.top().insert(name);
-    }
+  this->CheckForUnused("unsetting", name);
 #ifdef CMAKE_BUILD_WITH_CMAKE
   cmVariableWatch* vv = this->GetVariableWatch();
   if ( vv )
@@ -3391,19 +3418,7 @@ void cmMakefile::PopScope()
   for (; it != locals.end(); ++it)
     {
     init.erase(*it);
-    if (this->WarnUnused && usage.find(*it) == usage.end())
-      {
-      const char* cdir = this->ListFileStack.back().c_str();
-      if (this->CheckSystemVars ||
-          cmSystemTools::IsSubDirectory(cdir, this->GetHomeDirectory()) ||
-          cmSystemTools::IsSubDirectory(cdir, this->GetHomeOutputDirectory()))
-        {
-        cmOStringStream m;
-        m << "unused variable \'" << *it << "\'";
-        this->IssueMessage(cmake::AUTHOR_WARNING, m.str());
-        }
-      }
-    else
+    if (!this->CheckForUnused("out of scope", it->c_str()))
       {
       usage.erase(*it);
       }
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index f1ad54d..89979d6 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -840,7 +840,10 @@ public:
 protected:
   // add link libraries and directories to the target
   void AddGlobalLinkInformation(const char* name, cmTarget& target);
-  
+
+  // Check for a an unused variable
+  bool CheckForUnused(const char* reason, const char* name);
+
   std::string Prefix;
   std::vector<std::string> AuxSourceDirectories; // 
 

-----------------------------------------------------------------------

Summary of changes:
 Source/cmCommandArgumentParserHelper.cxx |    6 ++-
 Source/cmCoreTryCompile.cxx              |    4 +-
 Source/cmFunctionCommand.cxx             |    8 ++++
 Source/cmMakefile.cxx                    |   60 ++++++++++++++++++++++--------
 Source/cmMakefile.h                      |    7 +++-
 Source/cmStringCommand.cxx               |    2 +
 Source/cmake.cxx                         |    6 ++-
 Source/cmakemain.cxx                     |   10 +++--
 8 files changed, 75 insertions(+), 28 deletions(-)


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list